Time Limit: 1000MS | Memory Limit: 65536KB | 64bit IO Format: %lld & %llu |
Description
Unfortunately Fiona's stone is out of his jump range. Therefore Freddy considers to use other stones as intermediate stops and reach her by a sequence of several small jumps.
To execute a given sequence of jumps, a frog's jump range obviously must be at least as long as the longest jump occuring in the sequence.
The frog distance (humans also call it minimax distance) between two stones therefore is defined as the minimum necessary jump range over all possible paths between the two stones.
You are given the coordinates of Freddy's stone, Fiona's stone and all other stones in the lake. Your job is to compute the frog distance between Freddy's and Fiona's stone.
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 #2Frog Distance = 1.414
这题看懂题意后并没有联想到要用最短路写。。。
第一次用SPFA非常巧妙
#include <iostream> #include <queue> #include <cstring> #include <algorithm> #include <cstdio> #include <cmath> using namespace std; const int N = 1100; double x[N], y[N], frog[N]; const double inf= 0x3f3f3f3f; int main() { int n, t=1; while(scanf("%d", &n),n!=0) { for(int i=1;i<=n;i++) { scanf("%lf %lf", &x[i], &y[i]); } for(int i=1;i<=n;i++) { frog[i]=inf; } queue<int>q; while(!q.empty()) { q.pop(); } q.push(1); frog[1]=0; while(!q.empty()) { int k=q.front(); q.pop(); for(int i=1;i<=n;i++) { if(i==k) { continue; } double dis=max(sqrt((x[i]-x[k])*(x[i]-x[k])+(y[i]-y[k])*(y[i]-y[k])),frog[k]); if(dis<frog[i]) { frog[i]=dis; if(i!=2) { q.push(i); } } } } printf("Scenario #%d\n",t++); printf("Frog Distance = %.3f\n",frog[2]); printf("\n"); } return 0; }