首页 > 其他分享 >unique

unique

时间:2023-09-10 11:44:37浏览次数:46  
标签:unique 正整数 int 元素 include dis

unique

unique 是 c++ 标准函数库之一 ,需要配合头文件 #include<algorithm>使用
作用:‘去掉’容器中相邻元素的重复元素 ,伪去除,相当于将重复元素添加到容器末尾
使用前提: 容器内元素必须有序
结果:返回最后一个不重复元素的地址下标

int a[N];   
int dis = unique(a,a+n) - a;
//dis 为 去重后最后一个不重复元素的地址下标 
//例如 1 2 3 4 4    dis = 4   ; 1 2 3 3 4 4  dis = 4    

第 k 小整数

题目描述

现有 \(n\) 个正整数,要求出这 \(n\) 个正整数中的第 \(k\) 个最小整数(相同大小的整数只计算一次)。

输入格式

第一行为 \(n\) 和 \(k\); 第二行开始为 \(n\) 个正整数的值,整数间用空格隔开。

输出格式

第\(k\)个最小整数的值;若无解,则输出 NO RESULT

样例 #1

样例输入 #1

10 3
1 3 3 7 2 5 1 2 4 6

样例输出 #1

3

提示

\(n \leq 10000\),\(k \leq 1000\),正整数均小于 \(30000\)。

#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 100100;
int a[N];
int n,k;
int main()
{
	cin>>n>>k;
	for(int i = 0; i < n; i ++) cin>>a[i];
	sort(a,a + n);
	int dis = unique(a,a + n) - a;
	if(k < dis) cout<<a[k - 1];
	else cout<<"NO RESULT";
	return 0;
}

标签:unique,正整数,int,元素,include,dis
From: https://www.cnblogs.com/Elgina/p/17690956.html

相关文章

  • [转]Mysql中普通索引key 、主键索引(primary key) 、唯一索引(unique key)与index区别
    原文地址:Mysql中普通索引key、主键索引(primarykey)、唯一索引(uniquekey)与index区别-元小疯-博客园一、索引的定义和由来:    索引被用来快速找出在一个列上用一特定值的行。没有索引,MySQL不得不首先以第一条记录开始并然后读完整个表直到它找出相关的行。 ......
  • a build cache key that uniquely defines the task’s outputs based on its inputs
    BuildCachehttps://docs.gradle.org/current/userguide/build_cache.htmlTheGradle buildcache isacachemechanismthataimstosavetimebyreusingoutputsproducedbyotherbuilds.Thebuildcacheworksbystoring(locallyorremotely)buildoutputsan......
  • [LeetCode][62]unique-paths
    ContentThereisarobotonanmxngrid.Therobotisinitiallylocatedatthetop-leftcorner(i.e.,grid[0][0]).Therobottriestomovetothebottom-rightcorner(i.e.,grid[m-1][n-1]).Therobotcanonlymoveeitherdownorrightatanypointi......
  • LeetCode[62]UniquePaths
    ContentThereisarobotonanmxngrid.Therobotisinitiallylocatedatthetop-leftcorner(i.e.,grid[0][0]).Therobottriestomovetothebottom-rightcorner(i.e.,grid[m-1][n-1]).Therobotcanonlymoveeitherdownorrightatanypointi......
  • No_62_UniquePaths
    ContentThereisarobotonanmxngrid.Therobotisinitiallylocatedatthetop-leftcorner(i.e.,grid[0][0]).Therobottriestomovetothebottom-rightcorner(i.e.,grid[m-1][n-1]).Therobotcanonlymoveeitherdownorrightatanypointi......
  • C# 获取Windows系统设备唯一标识方法及代码(Unique Identifier)
    唯一的标识一个设备是一个基本功能,可以拥有很多应用场景,比如软件授权(如何保证你的软件在授权后才能在特定机器上使用)、软件License,设备标识,设备身份识别等。一、网卡MAC地址     MAC地址可能是最常用的标识方法,但是现在这种方法基本不可靠:一个电脑可能存在多个网卡,多个......
  • [ARC125D] Unique Subsequence
    设\(pre_i\)表示在\(i\)之前最后一个和\(i\)相同的数的位置,\(dp_i\)表示第\(i\)个数为结尾的序列的合法方案数。对于\(pre_i=0\),即在\(i\)之前不存在与\(i\)相同的数,\(dp_i\)由\(\left[1,i-1\right]\)转移过来。由于这个数还没有在之前出现过,它本身也是一......
  • c++中unique_ptr 的使用和理解
    unique_ptr的使用std::unique_ptr是c++11起引入的智能指针,为什么必须要在c++11起才有该特性,主要还是c++11增加了move语义,否则无法对对象的所有权进行传递。unique_ptr介绍unique_ptr不共享它的指针。它无法复制到其他unique_ptr,无法通过值传递到函数,也无法用于需要副本的......
  • [UNIQUE VISION Programming Contest 2023 Summer(AtCoder Beginner Contest 312) - A
    UNIQUEVISIONProgrammingContest2023Summer(AtCoderBeginnerContest312)-AtCoderA-Chord(atcoder.jp)#include<bits/stdc++.h>#defineendl'\n'usingnamespacestd;intmain(){vector<string>str{"ACE",&qu......
  • IfcGloballyUniqueId
    IfcGloballyUniqueId类型定义IfcGloballyUniqueId包含用于唯一标识IFC对象的编码字符串标识符。IfcGloballyUniqueId是一个全局唯一标识符(GUID),它是一个自动生成的128位数字。由于所有IFC对象实例都需要此标识符,因此需要对其进行压缩以减少开销。基本64个字符集的编码如下所示: ......