| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
【这题蛮有意思的】 小想法题,贴个思路首先我们定义一个 d*d的矩阵a,把 x y 分别 mod d 后,a[x][y]++;这样我们就知道了在一个矩阵中,这个点的位置,对于这个矩阵中,一个 十字 (一行和一列)的 数之和,就是一种方案,所以我们只需遍历一下就行了。。附代码
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
const int N=1000;
const int inf=1e9;
int a[N][N],d,n,nx[N],ny[N];
int main()
{
// freopen("in.txt","r",stdin);
int w;cin>>w;
while(w--)
{
scanf("%d%d",&d,&n);
memset(a,0,sizeof(a));
memset(nx,0,sizeof(nx));
memset(ny,0,sizeof(ny));
for(int i=0;i<n;i++)
{
int x,y;
scanf("%d%d",&x,&y);
x=(x+inf)%d;y=(y+inf)%d;
a[x][y]++;
nx[x]++;
ny[y]++;
}
int ans=inf;
for(int i=0;i<d;i++)
for(int j=0;j<d;j++) ans=min(ans,nx[i]+ny[j]-a[i][j]);
printf("%d\n",ans);
}
// cout << "Hello world!" << endl;
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator