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. Error:linker command failed with exit code 1 (use -v to see invocation) - iOS

    今天在操作 CoreData 时,创建完 Create NSManagedObject Subclass...  后,工程中会自动生成四个文件,如下图所示:   此时此刻便以工程,激动人心的时刻来临了 ...

  2. HTTP:地址栏输入url到显示页面的步骤

    在浏览器地址栏输入URL 浏览器查看缓存,如果请求资源在缓存中并且新鲜,跳转到转码步骤 如果资源未缓存,发起新请求 如果已缓存,检验是否足够新鲜,足够新鲜直接提供给客户端,否则与服务器进行验证. 检验 ...

  3. Map the Debris -freecodecamp算法题目

    Map the Debris 1.要求 返回一个数组,其内容是把原数组中对应元素的平均海拔转换成其对应的轨道周期. 原数组中会包含格式化的对象内容,像这样 {name: 'name', avgAlt: ...

  4. vim 个性化设置和操作

    一.vim 设置 1. 设置行号显示 1) 临时显示 命令行模式 :set nu 2) 永久显示 # vim ~/.vimrc 插入一行代码: set number 若没有该文件,在用户主目录 (/h ...

  5. 轻量级自动化工具 pssh

    pssh应用场景 pssh是一个用python编写的可以并发在多台服务器上批量执行命令的工具,它支持文件并行复制,远程并行执行命令,其中文件并行复制是pssh的核心功能,也是同类工具中的一个亮点. 要 ...

  6. 多线程(threading module)

    一.线程与进程 线程定义:线程是操作系统能够进行运算调度的最小单位.它被包含在进程之中,是进程中的实际运作单位.一条线程指的是进程中一个单一顺序的控制流,一个进程中可以并发多个线程,每条线程并行执行不 ...

  7. Ansible学习 Patterns

    Ansible中ad-hoc命令格式如下:ansible <pattern_goes_here> -m <module_name> -a <arguments>,P ...

  8. Java面试宝典2017版

    1. Java基础部分 基础部分的顺序:基本语法,类相关的语法,内部类的语法,继承相关的语法,异常的语法,线程的语法,集合的语法,io 的语法,虚拟机方面的语法. 1.一个".java&qu ...

  9. php结合redis实现高并发下的抢购、秒杀功能【转】

    抢购.秒杀是如今很常见的一个应用场景,主要需要解决的问题有两个:1 高并发对数据库产生的压力2 竞争状态下如何解决库存的正确减少("超卖"问题)对于第一个问题,已经很容易想到用缓存 ...

  10. 关于ZYNQ-700是否支持大容量SD卡汇报

    关于ZYNQ-700是否支持大容量SD卡 不支持. 下午问了客服的FAE给的答案是不清楚,我自己调研了一下为什么. 调查结果: 1. 大容量的SD卡为什么不支持? SD2.0规范中(SDHC)硬件支持 ...