P4305 [JLOI2011]不重复数字 set的应用


P4305 [JLOI2011]不重复数字
题解
判重,判断之前是否出现过该数,60%的数据在[0,104]所以这个数据可以使用桶的思想进行判重,100%数据在32位整数,且个数在5*104,且有50组,可以尝试set判重。

#include
using namespace std;
set<int> s;
vector<int> ans;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		s.clear();
		ans.clear();
		int n;
		cin>>n;
		for (int i=1;i<=n;i++)
		{
			int x;
			cin>>x;
			if (s.count(x)==0)
			{
				ans.push_back(x);
				s.insert(x);
			}
		}
		for (int i=0;icout<" ";
		}
		cout<<endl;
	}
	 
}



相关