unique函数
来源:互联网 发布:小暖医生软件 编辑:程序博客网 时间:2024/05/22 09:03
感觉大家在写离散化的时候好像都在用unique这个神奇的东西诶!
总结一下它的常用写法:
要离散的数组S, 数组大小len
sort(s, s + len);
len = unique(s, s + len) - s;
然后s[0]到s[len]就是离散化好的啦!
然后可以写一个二分来确定数的位置就行啦!
以下这段有点扯。。就是实验一下而已。
#include <iostream>#include <cstdio>#include <algorithm>#include <cmath>#include <cstring>using namespace std;int a[11] = {2, 1, 2, 3, 5, 2, 3, 8, 5, 5, 8};int main(){ int n = 10; sort(a + 1, a + n + 1); unique(a + 1, a + n + 1); for(int i = 0; i <= n; i ++)printf("%d ", a[i]); cout<<endl; // 除了前几位之外的好像都是乱的 sort(a + 1, a + n + 1); int *l; l = unique(a + 1, a + n + 1); cout<<l - a<<endl; //返回一个指针类型。。好像用它减数组返回的就是unique后的长度。 sort(a, a + n + 1); cout<<unique(a, a + n + 1) - a<<endl; //嗯嗯的确是的 sort(a + 4, a + 10); for(int i = 4; i <= 9; i ++)printf("%d ", a[i]); cout<<endl; cout<<unique(a + 4, a + 10) - a<<endl; //等等其实它实际上返回的是 第一位 没有被unique(就是混乱着的数)的下标。 system("pause"); return 0;}
0 0
- unique函数
- unique函数
- unique函数
- unique 函数
- unique函数
- unique函数
- unique函数
- unique函数
- unique函数
- unique函数
- 【unique函数】
- stl vector unique函数
- matlab unique函数
- STL-unique()函数
- unique() 去重函数
- matlab之unique函数
- matlab unique函数
- unique() 去重函数
- 2.2-找链表倒数第k个(same in LeetCode)
- C++设计模式-Mediator中介者模式
- 闭环(Closed Loop)
- 遍历Map的四种方法
- java 轻松学(填空题1)
- unique函数
- HDU 1285-确定比赛名次(裸拓扑||拓扑+前向星)
- Ubuntu12.04 不显示ibus
- 汇编的 DEBUG 命令
- android Device Admin以及hasSystemFeature(String string)
- 推荐系统3种主要算法学习笔记与总结
- 产生冠军(拓扑排序)
- 包含min方法的栈
- 紫蓝色的桂花果