这是一道之前总结过的最短路的变式:

Frogger

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.

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

题目大意:

一只青蛙要从1跳到2,而它不是要跳最短路程,而是要求一条路,这条路的要求是:在过程中每一次跳的距离要尽可能的小。即过程最大值的最小值(以边为准),这在之前的文章中总结过这种题型。看总结戳这

核心算式:dis[now]=min(dis[now],max(dis[pre],edge[i].w))

now是当前点维护的权值,pre是上一个点维护的权值,edge[i].w是pre->now的边长

根据这题的核心算式,可以考虑动态规划【Floyd】与之前说的最短路变式。

由于这题给的点较少,所以动态规划是可以的,如果太多只能用Dijistra或者spfa,因为mp二维数组只能只能开到1000个点。

动态规划的核心算法:

for (int k = 1; k <= n; k++)	
    for (int i = 1; i <= n; i++)			
        for (int j = 1; j <= n; j++)					
            map[i][j]= min(mp[i][j],max(map[i][k], map[k][j]))//就是始终求路径中的最大权边,并取最大权边的最小值

以下是最短路算法,以spfa为例,在这里说一下如果用dijikstra可能会比较快,spfa走了太多重复路,当然我也只是说可能,毕竟我看了以下网络大神的代码全是用dijikstra写的。

#include <queue>
#include <cstdio>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
using namespace std;
typedef long long ll;
const int maxn=1e6+5;
const int INF=1e9;
struct node1{
    int e;
    float w;
    int next;
}edge[maxn];
struct node2{
    int x,y;
}node[maxn];
int head[maxn];
float dis[maxn];
bool vis[maxn];
ll cnt=0;
double max1(double x,double y)
{
    return x-y>0?x:y;
}
void addedge(int u,int v,double w)
{
    edge[cnt].e=v;
    edge[cnt].w=w;
    edge[cnt].next=head[u];
    head[u]=cnt++;
}
void restart()
{
    memset(head,-1,sizeof(head));
    cnt=0;
}
void spfa(int n)
{
    for(int i=1;i<=n;i++) dis[i]=INF,vis[i]=false;
    queue<int>q;
    q.push(1);
    vis[1]=true;
    dis[1]=0;
    while(!q.empty())
    {
        int u=q.front();
        q.pop();
        vis[u]=false;
        for(int i=head[u];i!=-1;i=edge[i].next)
        {
            int e=edge[i].e;
            double x=max1(dis[u],edge[i].w);
            if(dis[e]-x>0)
            {
                dis[e]=x;
                q.push(e);
                vis[e]=true;
            }
        }
    }
}
int main()
{
    int n;
    int ans=0;
    while(scanf("%d",&n)&&n)
    {
        restart();
        double temp1,temp2;
        for(int i=1;i<=n;i++)
            scanf("%d%d",&node[i].x,&node[i].y);
        for(int i=1;i<=n;i++)
            for(int k=1;k<=n;k++)
            {
                if(i==k) continue;
                temp1=node[i].x-node[k].x;
                temp1*=temp1;
                temp2=node[i].y-node[k].y;
                temp2*=temp2;
                double d=sqrt(temp1+temp2);
                addedge(i,k,d);
            }
        spfa(n);
        printf("Scenario #%d\nFrog Distance = %.3f\n\n",++ans,dis[2]);
    }
    return 0;
}

PS:

1.这里我提交的时候,也不知道为什么要用float型提交,反正double过不了,这里求大神指点一下。

2.Dijikstra的那个算法的话,应该与最大生成树算法类似。