P4305 [JLOI2011]不重复数字 哈希表拉链式0分求助
  • 板块学术版
  • 楼主南瓜桐
  • 当前回复4
  • 已保存回复4
  • 发布时间2021/12/26 18:31
  • 上次更新2023/10/28 13:32:37
查看原帖
P4305 [JLOI2011]不重复数字 哈希表拉链式0分求助
439327
南瓜桐楼主2021/12/26 18:31

P4305 [JLOI2011]不重复数字

#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
const int maxn = 1e+5 + 3;
int t,n;
vector< vector<int> > h(maxn+10);
bool h_find(int a){
	int haxi = a%maxn;
	if(haxi<0){
		haxi*=-1;
	}
	haxi+=1;
	for(int i=0;i<h[haxi].size();i++){
		if(h[haxi][i]==a){
			return true;
		}
	}
	return false;
}
void h_insert(int a){
	int haxi = a%maxn;
	if(haxi<0){
		haxi*=-1;
	}
	haxi+=1;
	h[haxi].push_back(a);
}
int main(){
	std::ios::sync_with_stdio(false);
	cin>>t;
	do{
		for(int i=0;i<=h.size();i++){
			for(int j=0;j<h[i].size();j++){
				h[i][j]=0;
			}
		}
		cin>>n;
		int x=0;
		for(int i=1;i<=n;++i){
			cin>>x;
			if(h_find(x)==false){
				cout<<x<<' ';
				h_insert(x);
//				for(int i=1;i<=h[haxi].size();i++){
//					cout<<h[haxi][i]<<' ';
//				}
			}
		}
		cout<<endl;
	}while(--t);
	
	return 0;
}
/*
第一行一个整数 T,表示数据组数。

对于每组数据:

第一行一个整数 n。

第二行 n 个数,表示给定的数。
*/

Orz

2021/12/26 18:31
加载中...