P4305

[JLOI2011]不重复数字

题目描述

给定 \(n\) 个数,要求把其中重复的去掉,只保留第一次出现的数。

输入格式

本题有多组数据。

第一行一个整数 \(T\),表示数据组数。

对于每组数据:

第一行一个整数 \(n\)

第二行 \(n\) 个数,表示给定的数。

输出格式

对于每组数据,输出一行,为去重后剩下的数,两个数之间用一个空格隔开。

样例 #1

样例输入 #1

2
11
1 2 18 3 3 19 2 3 6 5 4
6
1 2 3 4 5 6

样例输出 #1

1 2 18 3 19 6 5 4
1 2 3 4 5 6

提示

对于 \(30\%\) 的数据,\(n \le 100\),给出的数 \(\in [0, 100]\)

对于 \(60\%\) 的数据,\(n \le 10^4\),给出的数 \(\in [0, 10^4]\)

对于 \(100\%\) 的数据,\(1 \le T\le 50\)\(1 \le n \le 5 \times 10^4\),给出的数在 \(32\) 位有符号整数范围内。

服了 真就万般皆上品 唯有cin是SB!
以后hash都用unordered_set或unordered_map
这题用关闭同步流的cin就TLE四个点!scanf read()都能过……
警示!!!
点击查看代码
#include<bits/stdc++.h>
using namespace std;
#define int long long
int t,n;
inline int read()
{
	char c=getchar();int x=0,f=1;
	for(;!isdigit(c);c=getchar())if(c=='-')f=-1;
	for(;isdigit(c);c=getchar())x=x*10+c-48;
	return x*f;
}
signed main()
{
	ios::sync_with_stdio(false);
	scanf("%lld",&t);
	while(t--)
	{
		unordered_set<int>st;
		scanf("%lld",&n);
		int x;
		for(int i=1;i<=n;i++)
		{
			scanf("%lld",&x);
			if(!st.count(x))
			{
				cout<<x<<" ";
				st.insert(x);
			}
		}
		cout<<"\n";
	}
	return 0;
}
posted @ 2023-01-08 15:41  PKU_IMCOMING  阅读(10)  评论(0)    收藏  举报