题解:
这类求从起点到终点的所有可行路径中权值最大的边最小的路之类的问题称为瓶颈路问题,也就是求在坐标0到坐标1的最短路中的最大边,这类问题同样符合Dijsktra的贪心思想,仍然可以按照找最短路的思路去找,只不过松弛条件从累加权值改为比较边的权值大小取最大。于是该问题同样可以使用最短路的思想及其对应算法解决。
注意如果使用%lf进行输入输出的时候提交要使用C++。POJ的毛病。
Description
Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fiona Frog who is sitting on another stone. He plans to visit her, but since the water is dirty and full of tourists' sunscreen, he wants to avoid swimming and instead reach her by jumping.
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.
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
The input will contain one or more test cases. The first line of each test case will contain the number of stones n (2<=n<=200). The next n lines each contain two integers xi,yi (0 <= xi,yi <= 1000) representing the coordinates of stone #i. Stone #1 is Freddy's stone, stone #2 is Fiona's stone, the other n-2 stones are unoccupied. There's a blank line following each test case. Input is terminated by a value of zero (0) for n.
Output
For each test case, print a line saying "Scenario #x" and a line saying "Frog Distance = y" where x is replaced by the test case number (they are numbered from 1) and y is replaced by the appropriate real number, printed to three decimals. Put a blank line after each test case, even after the last one.
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
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#define INF 999999999
#define LL long long
#define mod 1000003
using namespace std;
int n;
bool done[1005];
int d[1005];
struct node
{
double x,y;
};
node po[205];
struct HeapNode
{
int i;
double u;
HeapNode(int ii,double uu)
{
i=ii;
u=uu;
}
bool operator < (const HeapNode& rhs) const{
return u>rhs.u;
}
};
double dist(node a,node b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
double dijk()
{
priority_queue<HeapNode>q;
memset(done,0,sizeof(done));
q.push(HeapNode(0,0));
while(!q.empty())
{
HeapNode x=q.top();
q.pop();
int u=x.i;
if(u==1)//到达1就退出
return x.u;
if(done[u]) continue;
done[u]=true;
for(int i=0;i<n;i++)
{
if(!done[i])
{
double ddist=dist(po[u],po[i]);
if(ddist>x.u)//两种情况都要加入队列
q.push(HeapNode(i,ddist));
else
q.push(HeapNode(i,x.u));
}
}
}
}
int main()
{
int cnt=0;
while(scanf("%d",&n)&&n)
{
int a,b;
for(int i=0;i<n;i++)
{
scanf("%d %d",&a,&b);
po[i].x=a;
po[i].y=b;
}
printf("Scenario #%d\n",++cnt);
printf("Frog Distance = %.3lf\n\n",dijk());
}
}