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 |
很郁闷,WA了N 次 还不知哪错了,求测试数据#include<stdio.h> #define INF 999999 #define dis(x,y) ((x)*(x)+(y)*(y))//距离的平方,这样就不用double型 #define N 752 #define M 1005 int map[N][N]; int a[N];//用于输出时的前驱点 int n,m; int f[N]; int lesscost[N]; int main() { freopen("in.txt","r",stdin); int i,j; int min,min_i; int x1,y1; int x2[M],y2[M]; scanf("%d",&n); for(i=1;i<=n;i++) { scanf("%d%d",&x2[i],&y2[i]); } for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { map[i][j]=dis(x2[i]-x2[j],y2[i]-y2[j]); } } for(i=1;i<=n;i++) map[i][i]=INF; scanf("%d",&m); while(m--) { scanf("%d%d",&x1,&y1); map[x1][y1]=map[y1][x1]=0;//已有,不用在建 } for(i=1;i<=n;i++) { lesscost[i]=map[1][i]; a[i]=1;//从1开始 } f[1]=1; for(i=1;i<n;i++) { min=INF; for(j=1;j<=n;j++) { if(!f[j]&&lesscost[j]<min) { min=lesscost[j]; min_i=j; } } if(min>0) printf("%d %d\n",a[min_i],min_i); f[min_i]=1; for(j=1;j<=n;j++) { if(!f[j]&&lesscost[j]>map[min_i][j]) { lesscost[j]=map[min_i][j]; a[j]=min_i; } } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator