hnu 11028
那天比赛的, x %y 当 x%y<0的时候 (而不是x<0的时候) 应该取 y+x%y;
#include <stdio.h>

#include <string.h>

int tx[2000],ty[2000];
int f[2000][2000];
int main()
{
int t,i,j,ans,x,y,d,n;
scanf("%d",&t);
while (t--)
{
memset(f,0,sizeof(f));
memset(tx,0,sizeof(tx));
memset(ty,0,sizeof(ty));
scanf("%d%d",&d,&n);
for (i=0;i<n;i++)
{
scanf("%d%d",&x,&y);
tx[ x % d >= 0 ? x % d : d+x % d ]++;
ty[ y % d >= 0 ? y % d : d+y % d ]++;
f[ x % d >= 0 ? x % d : d+x % d ][ y % d >= 0 ? y % d : d+y % d ]++;
}
ans=n;
for (i=0;i<d;i++)
for (j=0;j<d;j++)
if (tx[i]+ty[j]-f[i][j]<ans) { ans=tx[i]+ty[j]-f[i][j];}
printf("%d\n",ans);
}
return 0;
}



浙公网安备 33010602011771号