前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >BZOJ2761: [JLOI2011]不重复数字(map)

BZOJ2761: [JLOI2011]不重复数字(map)

作者头像
attack
发布2019-01-30 16:05:04
6250
发布2019-01-30 16:05:04
举报

Time Limit: 10 Sec  Memory Limit: 128 MB

Submit: 6356  Solved: 2407

[Submit][Status][Discuss]

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来进行输入输出操作,以免浪费不必要的时间。

Source

看到这题比较水,然后就来切了。

感谢这道水题,让我知道了unique只能去重相邻元素

还让我知道了unordered_map怎么写。。

代码语言:javascript
复制
/**************************************************************
    Problem: 2761
    User: attack204
    Language: C++
    Result: Accepted
    Time:300 ms
    Memory:21856 kb
****************************************************************/
 
// luogu-judger-enable-o2
#include<cstdio>
#include<algorithm>
#include<map>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1<<22, stdin), p1 == p2) ? EOF : *p1++)
using namespace __gnu_pbds;
const int MAXN = 50001 + 1;
char buf[(1 << 22)], *p1 = buf, *p2 = buf;
using namespace std;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
char obuf[1<<24], *O=obuf;
void print(int x) {
    if(x > 9) print(x / 10);
    *O++= x % 10 + '0';
}
int a[MAXN];
cc_hash_table<int,bool>mp;
main() {
    int QwQ = read();
    while(QwQ--) {
        mp.clear();
        int N = read();
        for(int i = 1; i <= N; i++) {
            int x = read();
            if(!mp[x]) {
                mp[x] = 1;
                if(x < 0) *O++ = '-', x = -x;
                print(x); *O++ = ' ';
            }
        }
        *O++ = '\n';
    }
    fwrite(obuf, O-obuf, 1 , stdout);
    return 0;
}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018-06-10 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Description
  • Input
  • Output
  • Sample Input
  • Sample Output
  • HINT
  • Source
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档