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. 一篇SSM框架整合友好的文章(二)

    上一篇讲述了DAO 层,mybatis实现数据库的连接,DAO层接口设计,以及mybtis和spring的整合.DAO层采用接口设计方式实现,接口和SQL实现的分离,方便维护.DAO层所负责的仅仅是接 ...

  2. 日常运维管理技巧一(查看负载 W)

    日常运维管理技巧一(查看负载 W) 今天针对Linux系统管理做一个专题的记录,以后会用的几率也是很大的,只要掌握必备的基础知识,做初级系统管理员是不成问题的. 作为一个运维工程师.系统管理员,如果对 ...

  3. UVA_1434_YAPTCHA

    The math department has been having problems lately. Due to immense amount of unsolicited automated ...

  4. 基于mybatis设计简单信息管理系统2

    1.空指针异常 public class CanvasServlet extends HttpServlet { private CanvasService canvasService; privat ...

  5. VS2013使用自带的数据库 Microsoft SQL Server 2012 Express LocalDB

    注:DeptLocalDB:自己取的数据库实例名称 DeptSharedLocalDB:自己取的实例共享名称np:\\.\pipe\LOCALDB#SH7C6ED5\tsql\query:命名管道名称 ...

  6. SQl 语句(常见) 新建,删除,修改表结构

    2006-6-15 15:58:25 新建表:create table [表名]([自动编号字段] int IDENTITY (1,1) PRIMARY KEY ,[字段1] nVarChar(50) ...

  7. Python全栈day 06

    Python全栈day 06 一.数据类型补充完整 1. 列表(list) 反转reverse list1 = [1,2,3,4,5,6,7,8,9] list1.reverse() print(li ...

  8. python scrapy实战糗事百科保存到json文件里

    编写qsbk_spider.py爬虫文件 # -*- coding: utf-8 -*- import scrapy from qsbk.items import QsbkItem from scra ...

  9. 008---Django的模版层

    python的模板:HTML代码+模板语法 <!--模版语法之变量--> <h1>Index </h1> <p>{{ name }}</p> ...

  10. POJ:1222-EXTENDED LIGHTS OUT(矩阵反转)

    EXTENDED LIGHTS OUT Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12956 Accepted: 8186 ...