You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.2 KiB

2 years ago
#include <bits/stdc++.h>
using namespace std;
int t;//数据组数
int n;//表示给定的数
//哈希表 模板题
/**
2
11
1 2 18 3 3 19 2 3 6 5 4
6
1 2 3 4 5 6
:
1 2 18 3 19 6 5 4
1 2 3 4 5 6
*/
const int MOD = 1000003;
vector<int> linker[MOD + 10];//这相当于一个二维动态数组,一维是固定的,二维是动态的.一维对应着HASH后的值,二维是一个链表
int x; //每次读入的数字
//检查是不是出现过
bool insert(int val) {
int pos = (val % MOD + MOD) % MOD;//可以处理负数!如此处理,负数也要散列到正数的范围内!
for (int i = 0; i < linker[pos].size(); i++)
if (linker[pos][i] == val) return true;
//没有存在过,加进去
linker[pos].push_back(val);
return false;
}
int main() {
//不用scanf只使用cin会TLE掉后4个点
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
//初始化
memset(linker, 0, sizeof linker);
//一般读入,一边判断是否出现过
for (int i = 1; i <= n; i++) {
scanf("%d", &x);
if (!insert(x)) printf("%d ", x);
}
printf("\n");
}
return 0;
}