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<iostream> #include<cmath> using namespace std; #define INF 0x7f7f7f7f bool flag[220]; int closest[220]; double min_dist, x[220], y[220], lowcost[220], c[220][220]; int main(){ int n, i, j, k, num = 1; double min_dist, minimax; while(cin>>n){ if(n==0) break; for(i=1; i<=n; i++){ cin>>x[i]>>y[i]; } minimax = -1; memset(flag, 0, sizeof(flag)); flag[1] = 1; for(i=1; i<=n; i++){ for(j=1; j<=n; j++){ c[i][j] = sqrt(pow((x[j]-x[i]),2) + pow((y[j]-y[i]),2)); } } for(i=2; i<=n; i++){ closest[i] = 1; lowcost[i] = c[1][i]; } for(i=1; i<n; i++){ min_dist = INF; j = 1; for(k=2; k<=n; k++){ if(lowcost[k]<min_dist && flag[k]==0){ min_dist = lowcost[k]; j = k; } } flag[j] = 1; for(k=2; k<=n; k++){ if(c[j][k]<lowcost[k] && flag[k]==0){ lowcost[k] = c[j][k]; closest[k] = j; } } } for(i=1; i<=n; i++){ if(minimax < lowcost[i]) minimax = lowcost[i]; } printf("%s%d\n", "Scenario #", num++); printf("%s%.3f\n", "Frog Distance = ", minimax); } system("pause"); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator