标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 17569 Accepted Submission(s):
5477
#include<stdio.h> #include<algorithm> #include<math.h> int set[110]; using namespace std; struct record { double beg; double end; double ju; }s[11000]; int find(int fa) { int ch=fa; int t; while(fa!=set[fa]) fa=set[fa]; while(ch!=fa) { t=set[ch]; set[ch]=fa; ch=t; } return fa; } void mix(int x,int y) { int fx,fy; fx=find(x); fy=find(y); if(fx!=fy) set[fx]=fy; } double dis(int x1,int y1,int x2,int y2) { return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); } bool cmp1(record a,record b) { return a.ju<b.ju; } int main() { int n,m,j,i,island,q; double sum; int a[110],b[110]; scanf("%d",&n); while(n--) { scanf("%d",&island); for(i=1;i<=island;i++) set[i]=i; for(i=1;i<=island;i++) { scanf("%d%d",&a[i],&b[i]); } q=0; for(i=1;i<=island-1;i++) { for(j=i+1;j<=island;j++) { s[q].beg=i; s[q].end=j; s[q].ju=dis(a[i],b[i],a[j],b[j]); q++; } } sort(s,s+q,cmp1); sum=0; for(i=0;i<q;i++) { if(find(s[i].beg)!=find(s[i].end)&&s[i].ju>=10&&s[i].ju<=1000) { mix(s[i].beg,s[i].end); sum+=s[i].ju; } } m=0; for(i=1;i<=island;i++) { if(set[i]==i) m++; } if(m>1) printf("oh!\n"); else printf("%.1lf\n",sum*100); } return 0; }
标签:
原文地址:http://www.cnblogs.com/tonghao/p/4483021.html