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 |
那我打的是%lf也是G++就WA C++就過了In Reply To:G++的double是 %f Posted by:xg1990 at 2010-06-06 23:50:09 #include <cstdio> #include <algorithm> #include <cmath> using namespace std; struct node1{ double x,y; }; node1 a[110]; struct node{ int x,y;double c; }; node dic[5001]; int n,ans,f[110],xx,yy,num;double sum; int get(int x){ if(f[x]==0) return x; return f[x]=get(f[x]); } bool cmp(node x,node y){ if(x.c<y.c) return true; return false; } int main(){ scanf("%d",&n); for(int i=1;i<=n;++i) scanf("%lf%lf",&a[i].x,&a[i].y); for(int i=1;i<n;++i) for(int j=i+1;j<=n;++j) dic[++num].x=i,dic[num].y=j, dic[num].c=(a[i].x-a[j].x)*(a[i].x-a[j].x)+(a[i].y-a[j].y)*(a[i].y-a[j].y); sort(dic+1,dic+num+1,cmp); ans=n; for(int i=1;i<=num;++i){ xx=get(dic[i].x);yy=get(dic[i].y); if(xx!=yy){ --ans;f[xx]=yy;sum+=sqrt(dic[i].c); if(ans<=1) break; } } printf("%.2lf",sum); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator