【BZOJ2761】【hash】[JLOI2011]不重复数字 题解
来源:互联网 发布:查端口8080是否被占用 编辑:程序博客网 时间:2024/06/02 07:28
Description
给出N个数,要求把其中重复的去掉,只保留第一次出现的数。
例如,给出的数为1 2 18 3 3 19 2 3 6 5 4,其中2和3有重复,去除后的结果为1 2 18 3 19 6 5 4。
Input
输入第一行为正整数T,表示有T组数据。
接下来每组数据包括两行,第一行为正整数N,表示有N个数。第二行为要去重的N个正整数。
Output
对于每组数据,输出一行,为去重后剩下的数字,数字之间用一个空格隔开。
Sample Input
2
11
1 2 18 3 3 19 2 3 6 5 4
6
1 2 3 4 5 6
Sample Output
1 2 18 3 19 6 5 4
1 2 3 4 5 6
HINT
对于30%的数据,1 <= N <= 100,给出的数不大于100,均为非负整数;
对于50%的数据,1 <= N <= 10000,给出的数不大于10000,均为非负整数;
对于100%的数据,1 <= N <= 50000,给出的数在32位有符号整数范围内。
提示:
由于数据量很大,使用C++的同学请使用scanf和printf来进行输入输出操作,以免浪费不必要的时间。
#include <bits/stdc++.h>#define LL long long#define clr(x) memset(x, 0, sizeof x)#define ms(a, x) memset(x, a, sizeof x)#define digit (ch < '0' || ch > '9')using namespace std;template <class T> inline void read(T &x) { int flag = 1; x = 0; register char ch = getchar(); while( digit) { if(ch == '-') flag = -1; ch = getchar(); } while(!digit) { x = (x<<1)+(x<<3)+ch-'0'; ch = getchar(); } x *= flag;}const int maxn = 50005;int t,n,a[maxn],vis[maxn];struct NODE { int vl,id; inline bool operator < (const NODE &a) const { return a.vl > vl; }} b[maxn];int hsh(int x) { int l = 1, r = n; while(l < r) { int mid = (l+r)>>1; if(b[mid].vl >= x) r = mid; else l = mid+1; } return b[l].id;}int main () { read(t); while(t--) { clr(a); clr(vis); clr(b); read(n); for(int i = 1; i <= n; i++) read(a[i]), b[i].vl = a[i], b[i].id = i; sort(b+1, b+1+n); printf("%d",a[1]); for(int i = 2; i <= n; i++) if(!vis[hsh(a[i])]) printf(" %d",a[i]), vis[hsh(a[i])] = 1; if(t != 1) printf("\n"); } return 0;}
阅读全文
0 0
- 【BZOJ2761】【hash】[JLOI2011]不重复数字 题解
- 【bzoj2761】[JLOI2011]不重复数字
- bzoj2761 [JLOI2011]不重复数字
- [BZOJ2761][JLOI2011]不重复数字
- 【JLOI2011】【BZOJ2761】不重复数字
- bzoj2761 [JLOI2011]不重复数字
- 【bzoj2761】【JLOI2011】不重复数字
- bzoj2761 [JLOI2011]不重复数字
- bzoj2761 [JLOI2011]不重复数字
- BZOJ2761: [JLOI2011]不重复数字
- BZOJ2761 [JLOI2011]不重复数字
- 【BZOJ2761】[JLOI2011]不重复数字 STL set
- [BZOJ2761]JLOI2011不重复的数字
- 【bzoj2761】【JLOI2011】【不重复数字】【平衡树】
- [BZOJ2761][JLOI2011]不重复数字(splay)
- [bzoj-2761][JLOI2011]不重复数字 题解
- BZOJ2761 不重复数字
- [BZOJ2761] 不重复数字
- JavaScript
- 枚举关于Flags特性的使用
- 小白之路—杨辉三角
- Dvwa漏洞测试之文件包含笔记
- cookie和sessiong
- 【BZOJ2761】【hash】[JLOI2011]不重复数字 题解
- 11.1模拟赛总结
- 欢迎使用CSDN-markdown编辑器
- BZOJ 5044 [Lydsy 九月月赛] 构造 解题报告
- Hive 安装配置
- 文章标题
- nginx+vsftpd搭建图片服务器
- ubuntu16.04+NVIDIA GTX1050ti 显卡驱动PPA安装 +CUDA8.0
- mybatis逆向工程的创建和使用