Frogger(最短路_floyd变形)

Frogger

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 26435   Accepted: 8603

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
题意:其实就是石头0上的青蛙陶兄看上了石头1上的青蛙尹小姐,然后陶兄想去找尹小姐,但是奈何湖里垃圾太多过不去咋办,聪明的陶兄就想了个很好的办法找别的石头为中转站过去,求陶兄跳到尹小姐的过程中最短路径中最大步伐中的最小长度。
ps:英语渣比用了很长时间才搞懂到底是啥意思。很内伤。可能你看到这还不明白,请看下图,本屌字写的很烂,凑合看勿喷。


#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
struct node
{
    double x,y;
}edge[1010];
double map[1010][1010];
double distan(struct node a,struct node b)
{
     return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
int n,i,j,k;
void floyd()
{
    for(k=0;k<n;k++)
        for(i=0;i<n;i++)
        for(j=0;j<n;j++)
    {
        map[i][j]=min(map[i][j],max(map[i][k],map[k][j]));//最关键的地方,也是变形的地方
    }

}
int main()
{
    int cnt=1;
    while(~scanf("%d",&n))
    {
        if(n==0)
            break;
        for(i=0;i<n;i++)
            scanf("%lf %lf",&edge[i].x,&edge[i].y);
        for(i=0;i<n;i++)
            for(j=0;j<n;j++)
            map[i][j]=distan(edge[i],edge[j]);
        floyd();
        printf("Scenario #%d\n",cnt++);
        printf("Frog Distance = %.3lf\n\n",map[0][1]);
    }
    return 0;
}



时间: 2024-10-09 05:04:32

Frogger(最短路_floyd变形)的相关文章

POJ2253 Frogger —— 最短路变形

题目链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 49409   Accepted: 15729 Description Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fiona Frog who is sitting on a

C - Heavy Transportation &amp;&amp; B - Frogger(迪杰斯变形)

Background Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand business. But he needs a clever man who tells him whether there really is a way from the place his customer has build his giant steel crane to the place

11.3.4 例题11-5 UVA 247 Audiophobia(两点间最大权最小_floyd()变形)

题目大意: 给你一个n个节点,m条边的图,然后,给出q个询问,让你找出一条从u到v的路径中所经过的最大权值最小的路径权值. 解题思路: 直接使用floyd的变形来做. e[i][j] = min(e[i][j],e[i][k]+e[k][j])---->e[i][j] = min(e[i][j],max(e[i][k],e[k][j])); 代码: # include<cstdio> # include<iostream> using namespace std; # def

UVALive 4128 Steam Roller 蒸汽式压路机(最短路,变形) WA中。。。。。

题意:给一个由n*m个正方形格子组成的矩形,其中每个格子的边都是可以走的,长度给定,规定:如果在进入该路前需要拐弯,或者走完该路需要拐弯,都是需要付出双倍距离的(每条路最多算2倍).问从起点到终点的最短路经长. 思路:这个题目超级难搞,思路很简单,就是很麻烦!!!我将1个点4个方向的路长都记录下来,然后进行最短路,只要一个点的某个方向更新了,就进队.所有都考虑得差不多了,就是WA... 步骤 : (1)起点不进队,因为起点出发都需要双倍,况且,如果起点路长为0的话,其他点就不能路过起点了,所以将

Stockbroker Grapevine(最短路_floyd())

Stockbroker Grapevine Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 27478   Accepted: 15223 Description Stockbrokers are known to overreact to rumours. You have been contracted to develop a method of spreading disinformation amongst th

DAG求最短路--TSP变形--状压dp

DAG状压dp的一种 题目: $m$个城市,$n$张车票,第i张车票上的时间是$t_i$, 求从$a$到$b$的最短时间,如果无法到达则输出“impossible” 解法: 考虑状态:“现在在城市$v$,此时还剩下的车票的集合为$S$”这样的状态.从这个状态出发,使用一张车票移动到$i \in S$移动到相邻的城市$u$,就相当于转移到了“在城市$u$,此时还剩下的车票的集合为$S/ { i }$”这个状态. 把这个转移看成一条边,那么边上的花费就是(v-u间道路的长度)/ $t_i$.DAG上

poj1797(最短路小变形)

题目连接:http://poj.org/problem?id=1797 题意: 分析:dp[i]表示到达i点的过程中的最大承受重量,更新到i点时可能有多条路径,由优先队列堆出最大的那条即可. #include <cstdio> #include <cstring> #include <string> #include <cmath> #include <iostream> #include <algorithm> #include &

hdu 1625 Numbering Paths 最短路的变形,使用Floyd 外加判环

Numbering Paths Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 158    Accepted Submission(s): 47 Problem Description Problems that process input and generate a simple ``yes'' or ``no'' answer

人活着系列之开会(最短路_floyd)

人活着系列之开会 Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 人活着如果是为了事业,从打工的到老板的,个个都在拼搏,奋斗了多年终于有了非凡成就,有了一笔丰富的钱财.反过来说,人若赚取了全世界又有什么益处呢?生不带来,死了你还能带去吗?金钱能买保险,但不能买生命,金钱能买药品,但不能买健康,人生在世,还是虚空呀! 在苍茫的大海上,有很多的小岛,每个人都在自己的小岛上.又到了开会的时候了,鹏哥通过飞信告知了每个人,然后大家就开