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

题解:首先这道题不是让我们求最短路径,而是让我们去让我们找路径中最大值的最小值,并且n的范围是小于二百的,故可以用

floyed算法

接下来是代码:

提交的时候最好用G++,c++我的pow()函数好像

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
double a[201][201];
int b[201][3];
int main()
{
int n,cnt=1;
while(~scanf("%d",&n)&&n)
{
for (int i=1;i<=n;i++)
scanf("%d %d",&b[i][1],&b[i][2]);
for (int i=1;i<=n-1;i++)
{
for (int j=i+1;j<=n;j++)
a[i][j]=a[j][i]=sqrt(pow((b[i][1]-b[j][1]),2)+pow((b[i][2]-b[j][2]),2));
}
for (int k=1;k<=n;k++)
for (int i=1;i<=n;i++)
for (int j=2;j<=n;j++)
{
if (a[i][j]>a[i][k]&&a[i][j]>a[k][j])
{
if (a[i][k]>a[k][j])
a[i][j]=a[j][i]=a[i][k];
else
a[i][j]=a[j][i]=a[k][j];
}
}
printf("Scenario #%d\n",cnt++);
printf("Frog Distance = %.3f\n",a[1][2]);
printf("\n");
}
}

D - Frogger的更多相关文章

  1. POJ 2253 Frogger(Dijkstra)

    传送门 Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 39453   Accepted: 12691 Des ...

  2. 2016HUAS_ACM暑假集训3B - Frogger

    好几天没更新博客了,因为这周在看关于图论的算法,有好几个(还是英文名字-_-||),人晕晕的...... 说一下这个Frogger吧.这个题目的话......难的不是做法,而是题意... 大致题意:有 ...

  3. Frogger(floyd变形)

    Frogger Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Stat ...

  4. 最小瓶颈路 Uva 534 Frogger

    说明:关于Uva的题目,可以在vjudge上做的,不用到Uva(那个极其慢的)网站去做. 最小瓶颈路:找u到v的一条路径满足最大边权值尽量小 先求最小生成树,然后u到v的路径在树上是唯一的,答案就是这 ...

  5. POJ2253 Frogger

    Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 34865   Accepted: 11192 Descrip ...

  6. poj2253 最短路 floyd Frogger

    Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 28825   Accepted: 9359 Descript ...

  7. 最短路(Floyd_Warshall) POJ 2253 Frogger

    题目传送门 /* 最短路:Floyd算法模板题 */ #include <cstdio> #include <iostream> #include <algorithm& ...

  8. POJ 2253 Frogger

    题目链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissi ...

  9. poj 2253 Frogger dijkstra算法实现

    点击打开链接 Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 21653   Accepted: 7042 D ...

  10. POJ 2253 Frogger (最短路)

    Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 28333   Accepted: 9208 Descript ...

随机推荐

  1. JS写一个简单的程序,判断年份是平年还是闰年

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  2. equals()与hashCode()方法详解

    java.lang.Object类中有两个非常重要的方法: 1 2 public boolean equals(Object obj) public int hashCode() Object类是类继 ...

  3. 第二天:tomcat体系结构和第一个Servlet

    1.  打war包 2.  Tomcat体系再说明:   问题:如何去配置默认主机???    3.tomcat和servlet在网络中的位置 4.    servlet快速入门案例   1).开发s ...

  4. C++的继承与接口

    1.继承方式 三种继承方式,public,private,protected.注意,继承方式是相对于某一层类的方法而言,并不是相对于子类的对象而言.对于外部世界()对象来说,protected和pri ...

  5. memcache windows64 位安装

    --环境: windows 2008 R2 64位 wampserver2.2e-php5.3.13-httpd2.2.22-mysql5.5.24-x64 --目标: 实现 php 用memcach ...

  6. FactoryMethodPattern(23种设计模式之一)

    设计模式六大原则(1):单一职责原则 设计模式六大原则(2):里氏替换原则 设计模式六大原则(3):依赖倒置原则 设计模式六大原则(4):接口隔离原则 设计模式六大原则(5):迪米特法则 设计模式六大 ...

  7. Java Swing 创建转圈的进度提示框

    Java Swing 创建转圈的进度提示框 摘自 https://blog.csdn.net/nihaoqiulinhe/article/details/52439486 置顶2016年09月05日 ...

  8. 读取txt文件将文本行组合成特定格式

    有一网友要求从txt文本文件读取一些数据,然后组合为特定格式的数据行.原论题如下,刚才开始的要求描述得不太清楚,后来补充完整了. Insus.NET觉得本论题可有练习文本件读取功力,因此尝试实现一下. ...

  9. 《Effective Java》第8章 通用程序设计

    第47条:了解和使用类库 Top 100 Java Libraries on Github 2016 Library Number of Projects Type % of projects jun ...

  10. 《Effective Java》第9章 异常

    第58条:对可恢复的情况使用受检异常,对编程错误使用运行时异常 Java程序设计语言提供了三种可抛出结构(throwable) ;受检的异常(checked exception)运行时异常(run-t ...