Frogger
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 22557   Accepted: 7339

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

Source

dij:
 //348K    0MS    C++    1240B    2013-11-23 09:00:29
/* 题意:
给出n个石头,互相连通,青蛙要从第一个石头跳到第二个,求所有通路中最小的
各通路的最大跨步. 最短路径:
dij小变形,有点巧妙..看代码慢慢体会 */
#include<stdio.h>
#include<string.h>
#include<math.h>
struct node{
int x,y;
}p[];
int g[][];
int d[];
bool vis[];
int n;
int dis(node a,node b)
{
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
int max(int a,int b)
{
return a>b?a:b;
}
int min(int a,int b)
{
return a<b?a:b;
}
double dij()
{
memset(vis,false,sizeof(vis));
for(int i=;i<n;i++){
d[i]=g[][i];
}
vis[]=true;
while(!vis[]){ //遍历过第二个石头后就可跳出
int temp=0x7ffffff;
int v=;
for(int j=;j<n;j++)
if(!vis[j] && temp>d[j]){
temp=d[j];
v=j;
}
vis[v]=true;
for(int j=;j<n;j++)
if(!vis[j])
d[j]=min(max(d[v],g[v][j]),d[j]); //最小的最大步长
}
return sqrt(1.0*d[]);
}
int main(void)
{
int k=;
while(scanf("%d",&n),n)
{
for(int i=;i<n;i++)
scanf("%d%d",&p[i].x,&p[i].y);
for(int i=;i<n;i++)
for(int j=i+;j<n;j++)
g[i][j]=g[j][i]=dis(p[i],p[j]);
double ans=dij();
printf("Scenario #%d\n",k++);
printf("Frog Distance = %.3lf\n\n",ans);
}
return ;
}

floyd:

 //348K    47MS    C++    943B    2013-11-23 09:19:27
#include<stdio.h>
#include<string.h>
#include<math.h>
struct node{
int x,y;
}p[];
int g[][];
int n;
int dis(node a,node b)
{
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
int Max(int a,int b)
{
return a>b?a:b;
}
double floyd()
{
for(int k=;k<n;k++)
for(int i=;i<n-;i++)
for(int j=i+;j<n;j++)
if(g[i][k]<g[i][j] && g[k][j]<g[i][j])
g[i][j]=g[j][i]=Max(g[i][k],g[k][j]);
return sqrt(1.0*g[][]);
}
int main(void)
{
int k=;
while(scanf("%d",&n),n)
{
for(int i=;i<n;i++)
scanf("%d%d",&p[i].x,&p[i].y);
for(int i=;i<n-;i++)
for(int j=i+;j<n;j++)
g[i][j]=g[j][i]=dis(p[i],p[j]);
double ans=floyd();
printf("Scenario #%d\n",k++);
printf("Frog Distance = %.3lf\n\n",ans);
}
return ;
}

注意小细节:使用G++交的话要把printf中的 lf 改成 f ,否则会报错!

poj 2253 Frogger (最短路径)的更多相关文章

  1. 最短路(Floyd_Warshall) POJ 2253 Frogger

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

  2. POJ 2253 Frogger ,poj3660Cow Contest(判断绝对顺序)(最短路,floyed)

    POJ 2253 Frogger题目意思就是求所有路径中最大路径中的最小值. #include<iostream> #include<cstdio> #include<s ...

  3. POJ. 2253 Frogger (Dijkstra )

    POJ. 2253 Frogger (Dijkstra ) 题意分析 首先给出n个点的坐标,其中第一个点的坐标为青蛙1的坐标,第二个点的坐标为青蛙2的坐标.给出的n个点,两两双向互通,求出由1到2可行 ...

  4. POJ 2253 Frogger(dijkstra 最短路

    POJ 2253 Frogger Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fion ...

  5. POJ 2253 Frogger

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

  6. poj 2253 Frogger 最小瓶颈路(变形的最小生成树 prim算法解决(需要很好的理解prim))

    传送门: http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissi ...

  7. poj 2253 Frogger (dijkstra最短路)

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

  8. POJ 2253 ——Frogger——————【最短路、Dijkstra、最长边最小化】

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

  9. POJ 2253 Frogger Floyd

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

随机推荐

  1. 【Java】异常 —— throw, throws, try catch 相关内容

    嗯……面试考到了这个,又是一个如无意外 那么接下来就总结吧 一.什么是异常 程序运行过程中发生的异常事件. RuntimeException通常是因为编程员因为疏忽没有检查而引起的错误. 二.Exce ...

  2. Excle 常用函数

    1. 查找函数VLOOKUP 使用示例: =VLOOKUP(A1,$C$1:$D$19,2,0) 表示以A1单元格为基准,匹配C1开始到D19的范围数据,在公式行显示D单元格文本,也就是匹配范围的第二 ...

  3. NodeJS基础入门

    1.前端最主流的JavaScript运行环境 1>Node.js是一个基于Chrome V8引擎的JavaScript运行环境. 2>Node.js使用了一个事件驱动.非阻塞式I/O的模型 ...

  4. expect配合shell 实现自动分发秘钥文件

    expect使用场景 有时候需要批量地执行一些操作,或者执行自动化的操作的时候,有些指令需要交互式地进行这就会有很多麻烦,linux下有一个程序交expect,它可以模拟键盘输入文本,省去人工干预交互 ...

  5. ofbiz研究

    近段时间,刚有有时间研究了下ofbiz ; 目前还是刚开始,后期会记录过程 有一起研究的没

  6. Oracle常用傻瓜问题1000问

    Oracle常用傻瓜问题1000问 大家在应用ORACLE的时候可能会遇到很多看起来不难的问题, 特别对新手来说, 今天我简单把它总结一下, 发布给大家, 希望对大家有帮助! 和大家一起探讨, 共同进 ...

  7. 记 页面使用overflow-scroll在iOS上滑动卡顿的问题

    页面使用overflow-scroll在iOS上滑动卡顿的问题 因在做一个滑动的list列表,为某个div使用了overflow: scroll属性. 结果在手机上测试时,ios手机有明显的滑动卡顿问 ...

  8. stark组件(11):组合搜索

    效果图: 新增函数和类 Option 获取字段的对象或元组 SearchGroupRow 封装数据,展示到前端 get_search_group 获取组合搜索的字段 get_search_group_ ...

  9. [USACO12JAN]视频游戏的连击Video Game Combos(AC自动机+DP)

    Description 贝西正在打格斗游戏.游戏里只有三个按键,分别是“A”.“B”和“C”.游戏中有 N 种连击 模式,第 i 种连击模式以字符串 Si 表示,只要贝西的按键中出现了这个字符串,就算 ...

  10. 購買管理(MM)

    ■購買管理■ [購買伝票]EKKO: ヘッダ EKPO: 明細 EKET: 納入日程行 EKPA: 取引先機能 EKKN: 勘定設定 EKBE: 後続伝票 EKBEH: 削除済み後続伝票履歴 [請求書 ...