zoukankan      html  css  js  c++  java
  • 【JLOI 2011】 不重复的数字

    【题目链接】

               点击打开链接

    【算法】

               本题用map很好写,笔者用的是哈希的写法

    【代码】

               

    #include<bits/stdc++.h>
    using namespace std;
    #define MOD 10007
    #define MAXN 50010
    
    int T,n,len,i,x;
    int a[MAXN];
    vector<int> e[MOD];
    
    inline void Clear() {
            int i;
            for (i = 0; i < MOD; i++) e[i].clear();
    } 
    inline bool Find(int x) {
            int i,h;
            if (x < 0) h = (-x) % MOD;
            else h = x % MOD;
            for (i = 0; i < e[h].size(); i++) {
                    if (e[h][i] == x) return true;
            }    
            return false;
    }
    inline void ins(int x) {
            int h;
            if (x < 0) h = (-x) % MOD;
            else h = x % MOD;
            e[h].push_back(x);    
    }
    
    int main() {
            
            scanf("%d",&T);
            
            while (T--) {
                    len = 0;
                    scanf("%d",&n);
                    Clear();
                    for (i = 1; i <= n; i++) {
                            scanf("%d",&x);
                            if (!Find(x)) {
                                    a[++len] = x;
                                    ins(x);
                            }
                    }
                    for (i = 1; i < len; i++) printf("%d ",a[i]);
                    printf("%d
    ",a[len]);
            }
            
            return 0;
        
    }


  • 相关阅读:
    推箱子
    去掉两个最高分、去掉两个最低分,求平均分
    投票选班长
    彩票
    闰年、平年
    闹钟
    手机号抽奖
    for练习--侦察兵
    兔子、棋盘放粮食、猴子吃桃
    for练习--凑法
  • 原文地址:https://www.cnblogs.com/evenbao/p/9196359.html
Copyright © 2011-2022 走看看