【POJ】2253 Frogger

= =。请用C++提交。。

如果有朋友能告诉我G++和C++交题什么机制。。我感激不尽。G++杀我。


题目链接:http://poj.org/problem?id=2253

题意:青蛙A要去找B约会,水太脏了,只能跳石头过去。告诉你AB的坐标,然后告诉你中间石头的坐标。让你求最小最大边。emmm...就是最短路里头的最大边。QAQ。

题解:数据量不算大,floyd爆一发。就是在判断的时候改一下条件就好了。

代码:

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cmath>
 4 #include <cstring>
 5 using namespace std;
 6 const int maxn = 2005;
 7 
 8 struct node{
 9     double x;
10     double y;
11 };
12 
13 double dis(node a,node b){
14     return sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y) * (a.y - b.y));
15 }
16 
17 node frogs[maxn];
18 
19 double mp[maxn][maxn];
20 
21 int n;
22 
23 int main(){
24     int cas = 1;
25     while(cin>>n && n){
26         memset(mp,0,sizeof(mp));
27         for(int i = 0; i < n ;i++){
28             cin>>frogs[i].x>>frogs[i].y;
29         }
30         for(int i = 0; i < n ;i++){
31             for(int j = i+1 ;j < n ;j++){
32                 mp[i][j] = mp[j][i] = dis(frogs[i],frogs[j]);
33             }
34         }
35         for(int k = 0; k < n ;k++){
36             for(int i = 0; i < n ;i++){
37                 for(int j = 0; j < n ;j++){
38                     mp[i][j] = min(max(mp[i][k] , mp[k][j]), mp[i][j]);
39                 }
40             }
41         }
42         printf("Scenario #%d
",cas++);
43         printf("Frog Distance = %.3lf
",mp[0][1]);
44         cout<<endl; 
45     }
46 
47     return 0;
48 }
原文地址:https://www.cnblogs.com/Asumi/p/9702869.html