zoukankan      html  css  js  c++  java
  • BZOJ2761: [JLOI2011]不重复数字(map)

    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怎么写。。

    /**************************************************************
        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++ = '
    ';
        }
        fwrite(obuf, O-obuf, 1 , stdout);
        return 0;
    }
  • 相关阅读:
    np.newaxis
    UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 576-577: invalid continuation byte
    shell $() vs ${}
    install docker-ce for ubuntu
    ImportError: pycurl: libcurl link-time ssl backend (nss) is different
    saltstack install on centos7
    pycharm 用远程环境时报错bash: line 0: cd: /home/tmp: No such file or directory
    计算函用运行用时
    scrapy-redis
    merge dict key
  • 原文地址:https://www.cnblogs.com/zwfymqz/p/9163344.html
Copyright © 2011-2022 走看看