标签:rip clu minimum memory channel nat prim jin int
Time Limit: 3000MS | Memory Limit: 65536K | |
Description
Input
Output
Sample Input
4 0 0 0 0 1 1 1 1 2 1 0 3 0
Sample Output
1.000
Source
#include<cstdio> #include<algorithm> #include<cstring> #include<cmath> #define eps 1e-6 using namespace std; int n; double l,r,mid,ans,p; double x[1001],y[1001],h[1001],dis[1001][1001],cost[1001][1001],minn[1001],w[1001][1001]; bool v[1001]; bool check(double k) { p=0; memset(v,0,sizeof(v)); for(int i=1;i<=n;i++) minn[i]=w[1][i]; minn[1]=0;v[1]=true; int s=n-1; while(s--) { int point;double d=10000010; for(int i=1;i<=n;i++) if(!v[i]&&minn[i]<d) { point=i;d=minn[i]; } p+=d;v[point]=true; for(int i=1;i<=n;i++) if(!v[i]&&w[point][i]<minn[i]) minn[i]=w[point][i]; } return p>=0; } int main() { while(scanf("%d",&n)!=EOF) { if(!n) return 0; for(int i=1;i<=n;i++) scanf("%lf%lf%lf",&x[i],&y[i],&h[i]); for(int i=1;i<n;i++) for(int j=i+1;j<=n;j++) { dis[i][j]=sqrt(pow(abs(x[i]-x[j]),2)+pow(abs(y[i]-y[j]),2)); cost[i][j]=abs(h[i]-h[j]); } l=0,r=1000;ans=0; while(fabs(l-r)>eps) { mid=(l+r)/2; for(int i=1;i<n;i++) for(int j=i+1;j<=n;j++) w[i][j]=w[j][i]=cost[i][j]-mid*dis[i][j]; if(check(mid)) { ans=mid; l=mid+eps; } else r=mid-eps; } printf("%.3lf\n",ans); } }
标签:rip clu minimum memory channel nat prim jin int
原文地址:http://www.cnblogs.com/TheRoadToTheGold/p/6547745.html