POJ2253(floyd)

Frogger

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 32257   Accepted: 10396

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.

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所有每条路径最长的边中的最短的边。
#include"cstdio"
#include"cmath"
using namespace std;
double Max(double x,double y)
{
    if(x>y)    return x;
    else return y;
}
const int MAXN=1002;
const int INF=0x3fffffff;
struct Node{
    int x,y,index;
}a[MAXN];
double mp[MAXN][MAXN];
double distance(int i,int j)
{
    return sqrt((a[i].x-a[j].x)*(a[i].x-a[j].x)+(a[i].y-a[j].y)*(a[i].y-a[j].y));
}
int main()
{
    int cas=1;
    int n;
    while(scanf("%d",&n)!=EOF&&n)
    {
        for(int i=0;i<n;i++)
        {
            scanf("%d%d",&a[i].x,&a[i].y);
            a[i].index=i+1;
        }
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n;j++)
            {
                mp[a[i].index][a[j].index]=distance(i,j);
            }
        }
        for(int k=1;k<=n;k++)
            for(int i=1;i<=n;i++)
                for(int j=1;j<=n;j++)
                    if(mp[k][j]<mp[i][j]&&mp[i][k]<mp[i][j])
                    {
                        mp[i][j]=Max(mp[k][j],mp[k][i]);//mp[i][j]存放i->j路径中的最长边
                    }

        printf("Scenario #%d\n",cas++);
        printf("Frog Distance = %0.3f\n",mp[1][2]);
        printf("\n");
    }
    return 0;
}
时间: 2024-12-24 10:55:09

POJ2253(floyd)的相关文章

POJ2253 Frogger 【Floyd】

讲的是,一只雄青蛙要从一个石头到另外一个石头上去找某只雌青蛙,但是这两个石头隔得太远,青蛙跳不过去,所幸,湖面上还有很多其他石头,所以青蛙可以借助别的石头一步一步地跳向那只雌青蛙所在的石头.显然青蛙可能有多种路径,比如其中一条是 2,3,4,2,1 ,它跳了五次,数字代表每次跳的距离也就是路径上相邻两个石头之间的距离,那么这只青蛙的弹跳能力至少是4才能跳过去.在其他的路径中,可能要求青蛙的弹跳是5,是8,是1,是100,等等,这个问题求青蛙需要的最小弹跳能力.其实也就是个最大值中取最小的问题.

POJ2253——Frogger(Floyd变形)

Frogger DescriptionFreddy 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 swimm

poj2253 Frogger(Floyd)

题目链接 http://poj.org/problem?id=2253 题意 给出青蛙A,B和若干石头的坐标,现在青蛙A要跳到青蛙B所在的石头上,求出所有路径中最远那一跳的最小值. 思路 Floyd算法的变形,将求两点之间的最短路改成求两点之间最大边权的最小值即可. 代码 1 #include <algorithm> 2 #include <iostream> 3 #include <cstring> 4 #include <cstdio> 5 #inclu

floyd算法 poj2253

#include<iostream> #include<algorithm> #include<cmath> #include<cstdio> using namespace std; double dis[205][205]; int a[205],b[205],n; void floyd() { for(int k=1;k<=n;k++) for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) dis[i

poj2253 最短路 floyd Frogger

Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 28825   Accepted: 9359 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,

poj2253青蛙跳跃

1.floyd. 一个点到另一个点的最大距离,为所有路径最大距离的最小值(二分). 2.答案输出.%.3lf,%.3f,遇到精度问题,要多尝试. ********************************************** #include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespace std;const int maxn = 500;str

poj2253 Frogger(最短路变型或者最小生成树)

1 /* 2 题意:就是源点到终点有多条的路径,每一条路径中都有一段最大的距离! 3 求这些路径中最大距离的最小值! 4 5 Dijkstra, Floyd, spfa都是可以的!只不过是将松弛的条件变一下就行了! 6 7 想了一下,这道题用最小生成树做也可以啊,图总是连通的嘛!所以建一棵最小 8 生成树,然后dfs一下,从源点1,到终点2的路径上,查找边长最大的路径! 9 附上代码..... 10 */ 11 #include<iostream> 12 #include<cstdio&

POJ2253&amp;ZOJ1942--Frogger【SPFA】单源最短路变形

链接:http://poj.org/problem?id=2253 题意:一个青蛙在一块石头上,看到了另一个青蛙在另一块石头上,它想跳过去找它,如果距离太远它就需要借助别的石头当跳板,两块石头之间的青蛙距离被定义成两块石头之间所有路径中最大跳跃距离的最小值,求两个青蛙之间的青蛙距离. poj2263和它类似,链接:http://poj.org/problem?id=2263 解题报告:Here 这是最短路的变形,每两点之间都有路可以跳,更新最短路的值,权值记录成目前到这一点的最小青蛙距离就行了

POJ2263&amp;ZOJ1952--Heavy Cargo【Floyd】多源最短路变形

链接:http://poj.org/problem?id=2263 题意:有n个点,m条路,每条路双向的,现在卡车从某点到另一点,卡车的承载无上限,但是马路的承载有上限,问卡车应该承载多少才不会压坏马路. poj2253和它类似,链接:http://poj.org/problem?id=2253 解题报告:Here 就是在两点之间找一条路径,使路径中权值最小的那条边的权值最大,edge数组记录当前路径中最小权值边的权值 #include<cstring> #include<string&