最后四个RE,过了的大佬麻烦看一眼……
查看原帖
最后四个RE,过了的大佬麻烦看一眼……
184271
l55584楼主2021/6/6 22:06
#include <iostream>
#include <cstdio>
#include <string.h>
using namespace std;
int n;
	int a[50001];
	bool book[50001];
	int k[400001];
	bool t[50001];
bool zero=0;
int hash(int a)
{
	return a%400000;
}
int forward(int a)
{
	return (a+19260817)%400000;
}
void ans()
{
	memset(k,0,sizeof(k));
	memset(book,0,sizeof(book));
	zero=0;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=n;i++) if(a[i]<0) t[i]=1;
	for(int i=1;i<=n;i++)
	{
		if(a[i]==0)
		{
			if(zero) book[i]=1; else zero=1;
			continue;
		}
		int temp;
		if(t[i]) temp=hash(a[i]+19260817);
		else temp=hash(a[i]);
		while(k[temp]!=a[i]&&k[temp]!=0) temp=forward(temp);
		if(k[temp]==0) k[temp]=a[i];
		else book[i]=1;
	}
	for(int i=1;i<=n;i++) if(!book[i]) cout<<a[i]<<" ";
	cout<<"\n";
	return ;
}
int main()
{
	int t;
	cin>>t;
	for(int i=1;i<=t;i++)
	{
		ans();
	}
	return 0;
}

思路跟着第一篇题解走的,负数,0都判了

2021/6/6 22:06
加载中...