用了hash然后不知道哪里错了,求大佬帮我看看
  • 板块P1102 A-B 数对
  • 楼主Cell_xi
  • 当前回复2
  • 已保存回复2
  • 发布时间2020/12/9 17:13
  • 上次更新2023/11/5 06:21:25
查看原帖
用了hash然后不知道哪里错了,求大佬帮我看看
390605
Cell_xi楼主2020/12/9 17:13

一开始只有76,似乎是因为常数太小了,改大了之后到了92,但是之后换常数没用了

#include<cstdio>
#define MOD 1000003 
using namespace std;

int N,C;
long long ans;
struct node{
	int value;
	long long quant;
}a[MOD];

int main()
{
	scanf("%d%d",&N,&C);
	
	int temp;
	for(int i=1;i<=N;i++)
	{
		scanf("%d",&temp);
		a[temp%MOD].quant++;
		a[temp%MOD].value=temp;
	}
	
	for(int i=0;i<=MOD;i++)
	{
		temp=a[(a[i].value+C)%MOD].quant;
		if(a[i].quant){
			if(temp)
				ans+=temp*a[i].quant;
		}
	}
	printf("%lld",ans);
	return 0;
}
 
2020/12/9 17:13
加载中...