2761: [JLOI2011]不重复数字

2761: [JLOI2011]不重复数字

Time Limit: 10 Sec  Memory Limit: 128 MB
Submit: 4128  Solved: 1544
[ Submit][ Status][ Discuss]

Description

给出N个数,要求把其中重复的去掉,只保留第一次出现的数。
例如,给出的数为1 2 18 3 3 19 2 3 6 5 4,其中2和3有重复,去除后的结果为1 2 18 3 19 6 5 4。
 

Input

输入第一行为正整数T,表示有T组数据。
接下来每组数据包括两行,第一行为正整数N,表示有N个数。第二行为要去重的N个正整数。
 

Output

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

Sample Input

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

Sample Output

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

HINT

对于30%的数据,1 <= N <= 100,给出的数不大于100,均为非负整数;


对于50%的数据,1 <= N <= 10000,给出的数不大于10000,均为非负整数;


对于100%的数据,1 <= N <= 50000,给出的数在32位有符号整数范围内。


提示:


由于数据量很大,使用C++的同学请使用scanf和printf来进行输入输出操作,以免浪费不必要的时间。


Source

[ Submit][ Status][ Discuss]



强力hash一波。。终于用上了Mektpoy传授的vector版hash。。

不过此题PE是什么鬼--

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
#include<ext/pb_ds/priority_queue.hpp>
using namespace std;

const int maxn = 5E4 + 50;
const int mo = 10000007;

int n,T,cnt,last,A[maxn],bo[maxn];

vector <int> v[mo];

int getint()
{
	char ch = getchar();
	int ret = 0,a = 1;
	while (ch < '0' || '9' < ch)
	{
		if (ch == '-') a = -1;
		ch = getchar();
	}
	while ('0' <= ch && ch <= '9')
		ret = ret*10 + ch - '0',ch = getchar();
	return ret*a;
}

bool hash_insert(int x)
{
	int pos = (x%mo+mo)%mo;
	for (int i = 0; i < v[pos].size(); i++)
		if (x == v[pos][i]) return 0;
	v[pos].push_back(x); return 1;
}

void hash_del(int x)
{
	int pos = (x%mo+mo)%mo; v[pos].clear();
}

int main()
{
	#ifdef DMC
		freopen("DMC.txt","r",stdin);
	#endif
	
	T = getint();
	for (int I = 1; I <= T; I++)
	{
		n = getint(); ++cnt;
		for (int i = 1; i <= n; i++)
		{
			A[i] = getint();
			if (hash_insert(A[i])) bo[i] = cnt,last = i;
		}
		for (int i = 1; i <= n; i++) 
		{
			hash_del(A[i]);
			if (bo[i] == cnt) printf("%d",A[i]);
			if (i != last && bo[i] == cnt) putchar(' ');
		}
		if (I != T) puts("");
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值