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. WampServer无法直接打开myprojects的解决方法

    https://jingyan.baidu.com/article/7e4409533ace042fc1e2ef40.html

  2. XMPP资源绑定(Resource Binding)

    一个XMPP的账号由三部分组成: 用户名(user/node),域名(domain)和资源(resource) .例如 alice@xmpp.irusher.com/mobile ,user部分(或n ...

  3. mnesia的脏读和事物读的测试

    在mnesia中,有脏读脏写等以及事物读写,它们的差异通过测试不难发现: 代码如下: -module(mnesia_read_test). -compile(export_all). -record( ...

  4. PowerBuilder -- 数据窗口

    获取数据窗口列数 ls_colnum= integer(this.Describe("DataWindow.Column.Count")) 获取数据窗口列名 ls_colName ...

  5. Android Apk包下查看 sha1

    用keytool工具查看sha1,格式如下:keytool -printcert -file  Urovo.RSA文件路径(APK解压后在Meta-INF文件夹下)

  6. 搭建sftp服务+nginx代理

    在公司,经常会用到sftp服务,比如两个公司对接生产项目,其中一方,要在sftp上上传pdf文件,另一方公司要在sftp服务器上用nginx代理直接下载pdf文件.下面就说说我在实际中应用到的sftp ...

  7. EasyPlayerPro windows播放器之多窗口播放音量控制方法

    EasyPlayerPro-win基础版本的音频播放为单一通道播放,即同一时间仅允许一个通道播放声音,现应客户需求,在基础版本上实现独立的音频播放,即每个通道可同时播放视频和音频; 设计思路 将音频播 ...

  8. JavaScript中实现继承

    今天即兴研究了下JS,查阅了相关资料 ,发现Js中没有"子类"和"父类"的概念,也没有"类"(class)和"实例"(i ...

  9. k-anonymity

    k匿名(k-anonymity)是一种常用的社交网络隐私保护技术,其思想是通过人为构造一定数量与目标节点拓扑结构相同的节点来降低用户被定位的概率 [匿名]英语怎么说_在线翻译_有道词典 http:// ...

  10. Android笔记之ViewModel的使用示例

    依赖 implementation 'android.arch.lifecycle:extensions:1.1.1' implementation 'com.squareup.retrofit2:r ...