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. 改变shape solid color

    <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http: ...

  2. virtual base classes

    virtual base classes用来实现菱形继承解决多个重复subobject的问题 //: C09:VirtualBase.cpp // Shows a shared subobject v ...

  3. 使用免费公开的api接口示例(iOS)

    做项目难免需要测试,要测试就需要一些接口,现在网上的很多接口都是需要收费的. 以下是目前找到的免费 JSON API免费接口 云聚数据 网吧数据 其中选取了一个百度百科的接口 百度接口 百度百科接口: ...

  4. poj_1320_Street Numbers

    A computer programmer lives in a street with houses numbered consecutively (from 1) down one side of ...

  5. Ansible学习 Playbooks_1

    Playbooks是Ansible中执行较复杂任务的一种的方式,Playbook由1个或多个play组成,语法格式是YAML,下面以一个简单的任务为例,开始我们的Playbook学习: 任务描述: 1 ...

  6. php中==和===的含义及区别

    ===比较两个变量的值和类型:==比较两个变量的值,不比较数据类型. 比如 $a = '123'; $b = 123; $a === $b为假: $a == $b为真: 有些情况下不能使用==,可以使 ...

  7. python——闰年的判断

    写一个程序,判断给定年份是否为闰年. 这样定义闰年的:能被4整除但不能被100整除,或者能被400整除都是闰年. while(1): year = input("请输入一个年份,让我判断一下 ...

  8. [Link-Cut-Tree][BZOJ2631]Tree

    题面 Description: 一棵\(n\)个点的树,每个点的初始权值为\(1\).对于这棵树有\(q\)个操作,每个操作为以下四种操作之一: + u v c:将\(u\)到\(v\)的路径上的点的 ...

  9. 笔记-docker-2安装(centos6.5环境)

    笔记-docker-2安装(centos6.5环境) 1.      centos6.5安装docker 1.1.    升级内核 安装docker,官方文档要求linux kernel至少3.8以上 ...

  10. Matplotlib库介绍

    pyplot的plot()函数 pyplot的中文显示 pyplot的文本显示 pyplot的子绘图区域