首页 > 其他分享 >P4305 [JLOI2011]不重复数字

P4305 [JLOI2011]不重复数字

时间:2023-02-18 19:11:58浏览次数:48  
标签:return JLOI2011 重复 hs int P4305 --

题目链接:https://www.luogu.com.cn/problem/P4305

方法一:哈希表

#include<bits/stdc++.h>
using namespace std;
const int P=10007;
int t, n;
vector <int> hs[P];
int f(int x){
	return (x%P+P)%P;
}
bool get(int k){
	if(hs[f(k)].size()==0)
		return 0;
	else{
		for(int i=0; i<hs[f(k)].size(); i++)
			if(hs[f(k)][i]==k)return 1;
		return 0;
	}
}
void add(int k){
	hs[f(k)].push_back(k);
}
bool hash_table(int k){
	if(get(k))
		return 0;
	else{
		add(k);
		return 1;
	}	
}

int main()
{
	cin>>t;
	while(t--){
		cin>>n;
		while(n--){
			int x;
			cin>>x;
			if(hash_table(x))
				cout<<x<<" ";
		}
		cout<<endl;
		memset(hs, 0, sizeof(hs));
		//hs[P].clear();
	}

	return 0;
}

标签:return,JLOI2011,重复,hs,int,P4305,--
From: https://www.cnblogs.com/tflsnoi/p/17133311.html

相关文章