标签:
Description
Input
Output
Sample Input
2 0 0 3 4 3 17 4 19 4 18 5 0
Sample Output
Scenario #1 Frog Distance = 5.000 Scenario #2 Frog Distance = 1.414
Source
#include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; int const MAX = 300,inf = 0x3f3f3f3f; double map[MAX][MAX]; struct edge{ double x,y; }edge[MAX]; int main(){ int n, count = 1;; while(~scanf("%d",&n)&&n){ for(int i = 1;i <= n ;i++) scanf("%lf%lf",&edge[i].x,&edge[i].y); for(int i = 1; i <= n; i++){ for(int j = i+1; j <= n ;j++){ map[i][j] = sqrt((double)(edge[j].x-edge[i].x)*(edge[j].x-edge[i].x)+(edge[j].y-edge[i].y)*(edge[j].y-edge[i].y)); map[j][i] = sqrt((double)(edge[j].x-edge[i].x)*(edge[j].x-edge[i].x)+(edge[j].y-edge[i].y)*(edge[j].y-edge[i].y)); } } for(int k = 1; k <= n ; k++){ for(int i = 1; i <= n ; i++){ for(int j = 1; j <= n ;j++){ if(map[i][j] > max(map[i][k],map[k][j])) map[i][j] = max(map[i][k],map[k][j]);//因为能往回走 } } } printf("Scenario #%d\n",count); printf("Frog Distance = %.3lf\n\n",map[1][2]); count++; } return 0; }
标签:
原文地址:http://www.cnblogs.com/zero-begin/p/4320257.html