标签:des blog http io ar os sp for strong
Description
Input
Output
Sample Input
Sample Output
#include <iostream> #include <queue> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cstring> using namespace std; int p[100][100]; int main() { int n,m,x,y; while(scanf("%d %d",&n,&m)&&n&&m) { memset(p,0,sizeof(p)); for(int i=0;i<n*n;i++) { scanf("%d %d",&x,&y); p[x][0]++; p[x][p[x][0]]=y; } for(int i=1;i<=n;i++) sort(p[i]+1,p[i]+n+1); int sum=0,minn=1000000000; for(int i=1;i<=m-n+1;i++) { sum=0; for(int j=1;j<=n;j++) for(int k=1;k<=n;k++) { sum+=abs(i-1+k-p[j][k]); } minn=min(sum,minn); } printf("%d\n",minn); } return 0; }
hdu 3687 10 杭州 现场 H - National Day Parade 暴力水题
标签:des blog http io ar os sp for strong
原文地址:http://www.cnblogs.com/xuesu/p/4085677.html