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=;
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=;
int n;
while(scanf("%d",&n)!=EOF&&n)
{
for(int i=;i<n;i++)
{
scanf("%d%d",&a[i].x,&a[i].y);
a[i].index=i+;
}
for(int i=;i<n;i++)
{
for(int j=;j<n;j++)
{
mp[a[i].index][a[j].index]=distance(i,j);
}
}
for(int k=;k<=n;k++)
for(int i=;i<=n;i++)
for(int j=;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[][]);
printf("\n");
}
return ;
}

dijkstra:

#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
const int MAXN=;
const int INF=0x3f3f3f3f;
struct Node{
int x,y;
}stone[MAXN];
int n;
double mp[MAXN][MAXN];
double dist(int x1,int y1,int x2,int y2)
{
return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
double d[MAXN];
int vis[MAXN];
double dijkstra(int s)
{
for(int i=;i<=n;i++)
{
d[i]=mp[s][i];
vis[i]=;
}
int t=n;
while(t--)
{
double mincost=INF;
int k;
for(int i=;i<=n;i++)
{
if(!vis[i]&&mincost>d[i])
{
mincost=d[i];
k=i;
}
}
vis[k]=;
for(int i=;i<=n;i++)
{
if(!vis[i]&&d[i]>max(d[k],mp[k][i]))
{
d[i]=max(d[k],mp[k][i]);
}
}
}
return d[];
}
int main()
{
int t=;
while(scanf("%d",&n)!=EOF&&n!=)
{
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
if(i==j) mp[i][j]=;
else mp[i][j]=INF; for(int i=;i<=n;i++)
{
scanf("%d%d",&stone[i].x,&stone[i].y);
}
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
{
double d=dist(stone[i].x,stone[i].y,stone[j].x,stone[j].y);
mp[i][j]=mp[j][i]=d;
}
} printf("Scenario #%d\n",++t);
printf("Frog Distance = %.3f\n\n",dijkstra());//.lf会WA
}
return ;
}

POJ2253(djkstra求最长最短边)的更多相关文章

  1. AC日记——最长最短单词 openjudge 1.7 25

    25:最长最短单词 总时间限制:  1000ms 内存限制:  65536kB 描述 输入1行句子(不多于200个单词,每个单词长度不超过100),只包含字母.空格和逗号.单词由至少一个连续的字母构成 ...

  2. spfa求最长路

    http://poj.org/problem?id=1932 spfa求最长路,判断dist[n] > 0,需要注意的是有正环存在,如果有环存在,那么就要判断这个环上的某一点是否能够到达n点,如 ...

  3. Manacher算法 - 求最长回文串的利器

    求最长回文串的利器 - Manacher算法 Manacher主要是用来求某个字符串的最长回文子串. 不要被manacher这个名字吓倒了,其实manacher算法很简单,也很容易理解,程序短,时间复 ...

  4. 后缀数组 - 求最长回文子串 + 模板题 --- ural 1297

    1297. Palindrome Time Limit: 1.0 secondMemory Limit: 16 MB The “U.S. Robots” HQ has just received a ...

  5. 后缀数组(模板题) - 求最长公共子串 - poj 2774 Long Long Message

    Language: Default Long Long Message Time Limit: 4000MS   Memory Limit: 131072K Total Submissions: 21 ...

  6. HDU 1025 Constructing Roads In JGShining's Kingdom(求最长上升子序列nlogn算法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1025 解题报告:先把输入按照r从小到大的顺序排个序,然后就转化成了求p的最长上升子序列问题了,当然按p ...

  7. HDU 4612 Warm up tarjan缩环+求最长链

    Warm up Problem Description   N planets are connected by M bidirectional channels that allow instant ...

  8. [algorithm]求最长公共子序列问题

    最直白方法:时间复杂度是O(n3), 空间复杂度是常数 reference:http://blog.csdn.net/monkeyandy/article/details/7957263 /** ** ...

  9. hdu 3068 最长回文(manachar求最长回文子串)

    题目连接:hdu 3068 最长回文 解题思路:通过manachar算法求最长回文子串,如果用遍历的话绝对超时. #include <stdio.h> #include <strin ...

随机推荐

  1. 一张图帮你看懂 iPhone 6 Plus 的屏幕分辨率

    一张图帮你看懂 iPhone 6 Plus 的屏幕分辨率 几天前公布的 iPhone 6 Plus 官方标称屏幕是 1920 x 1080 的,可是在 Xcode 中我们发现模拟器的屏幕事实上是看似奇 ...

  2. 关于HDFS NFS3的配置

    1.在core-site.xml中配置 <property> <name>hadoop.proxyuser.root.groups</name> <value ...

  3. 通过PHP获取文件创建与修改时间

    1.获取文件创建时间示例: 1 2 $ctime=filectime("chinawinxp.txt"); echo "创建时间:".date("Y- ...

  4. windows 2008配置运行PHP5.5.X

    1.安装web5.0平台安装程序.web5.0平台安装程序:http://www.iis.net/downloads (实际上更方便的是用WebPlalform安装PHP:http://www.mic ...

  5. [Android基础]Android中使用HttpURLConnection

    HttpURLConnection继承了URLConnection,因此也能够向指定站点发送GET请求.POST请求.它在URLConnetion的基础上提供了例如以下便捷的方法. int getRe ...

  6. linux 打印系统时间操作

    版权为个人所有,如需转载请说明出处.(东北大亨) http://www.cnblogs.com/northeastTycoon/p/5511498.html 1. 打开shell脚本 例子1:输出两天 ...

  7. Java 学习 day01

    1. 基本常识 2. Java的跨平台性 3. Java环境搭建(安装) 4. Java环境搭建(环境变量配置) 5. Java环境搭建(环境变量配置技巧) 6. Java环境搭建(环境变量临时配置方 ...

  8. VS2013 自动添加头部注释 -C#开发

    在团队开发中,头部注释是必不可少的.但在开发每次新建一个类都要复制一个注释模块也很不爽,所以得想个办法让开发工具自动生成我们所需要的模板.....操作方法如下: 方法/步骤 1 找你的vs安装目录, ...

  9. 云服务器 ECS Linux CentOS 修改内核引导顺序

    由于 CentOS 7 使用 grub2 作为引导程序,所以和 CentOS 6 有所不同,并不是修改 /etc/grub.conf 来修改启动项,需要如下操作: 1. 查看系统内部有多少个内核: c ...

  10. ubuntu中设置wireshark抓包

    安装wireshark软件后,打开进行抓包的时候会提示权限不足.原因是普通用户没有执行权限,也打不开网络端口捕捉,因为dumpcap需要root权限. 产生这种问题的原因:比如:wireshark在进 ...