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 |
RE怎么解决,求高手//我的总是RE有哪位能帮我看看近段时间做这类题贡献了无数RE #include<stdio.h> #include<string.h> #include<iostream> #include<cmath> #define inf 0x3fffffff using namespace std; double map[105][105]; typedef struct Node{ double x,y,z; double r; }node; node no[105]; double prim(int n) { int visit[30]={0}; double dis[30]; double sum,min; int i,j,k; sum=0; for(i=1;i<=n;++i) dis[i]=map[1][i]; visit[1]=1; for(i=2;i<=n;++i) { min=inf; k=1; for(j=1;j<=n;++j) { if(!visit[j]&&min>dis[j]) { min=dis[j]; k=j; } } visit[k]=1; if(min!=inf) sum+=min; for(j=1;j<=n;++j) { if(!visit[j]&&dis[j]>map[k][j]) dis[j]=map[k][j]; } } return sum; } int main() { int n,len,k,i,j; while(scanf("%d",&n),n) { memset(map,inf,sizeof(map)); for(int i=1;i<=n;i++)map[i][i]=0; for(i=1;i<=n;++i) { double x,y,z;double r; scanf("%lf%lf%lf%lf",&no[i].x,&no[i].y,&no[i].z,&no[i].r); } for(int i=1;i<=n;i++) for(int j=i+1;j<=n;j++){ double d; node a=no[i],b=no[j]; d=sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+(a.z-b.z)*(a.z-b.z)); if(d > no[i].r + no[j].r) { map[i][j] = map[j][i] = d - no[i].r - no[j].r; } else { map[i][j] = map[j][i] = 0; } } double answer; answer=prim(n); if(abs(answer-0)<0.0001)cout<<"0.00"<<endl; else printf("%.3lf\n",answer); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator