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 |
请指教#include<stdio.h> #include<memory.h> #include<math.h> struct spot{ double x,y; }s[105]; int n,mark[100],nMark; double dis,tem,mindis=1000000; void main() { scanf("%d",&n); for(int i=0;i<n;i++) scanf("%lf %lf",&s[i].x,&s[i].y); for(int head=0;head<n;head++){ i=head; memset(mark,0,sizeof(mark)); dis=0; int k=1; mark[i] = 1; while(k<n){ tem=1000000; for(int j=0;j<n;j++) if(mark[j])continue; else { double temp = (s[i].x-s[j].x)*(s[i].x-s[j].x) + (s[i].y-s[j].y)*(s[i].y-s[j].y); if(temp < tem){ tem = temp; nMark = j; } } dis+=sqrt(tem); mark[nMark] = 1; i=nMark; k++; } if(dis < mindis) mindis=dis; } printf("%.2lf\n",mindis); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator