题目链接:http://poj.org/problem?id=2253

Frogger
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 38366   Accepted: 12357

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 题目大意:input 第一行的n代表 在一个湖中有n个石头,接下来是每个石头的坐标,Freddy在第一个石头上,Fiona在第二个石头上,找出一条最短路径使的
Freddy跳到Fiona所在的石头上,输出这条路径中他需要跳的最远的一次的距离。

解题思路: 迪杰斯特拉算法的应用 将dis数组中的值变成最短路径中的最大权值
AC代码:
 #include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <iostream>
#include <iomanip>
using namespace std;
#define inf 999999999
double dis[];
int visit[];
double p[][];
int n;
void dijkstra()
{
int i,j,pos = ,minn;
memset(visit,,sizeof(visit));
visit[] = ;
dis[] = ;
for (i = ; i <= n; i ++)
dis[i] = p[][i]; for (i = ; i <= n; i ++)
{
minn = inf;
for (j = ; j <= n; j ++)
{
if (!visit[j] && dis[j] < minn)
{
minn = dis[j];
pos = j;
}
}
visit[pos] = ;
if (pos == )
break;
for (j = ; j <= n; j ++) //将dis数组中的值变成最短路径中的最大权值
{
if (!visit[j] && dis[j] > max(dis[pos],p[pos][j]))
dis[j] = max(dis[pos],p[pos][j]);
}
}
}
int main ()
{
double x[],y[];
int i,j,f = ;
while (~scanf("%d",&n))
{
if (n == )
break;
for (i = ; i <= n; i ++)
for (j = ; j <= n; j ++)
p[i][j] = inf; for (i = ; i <= n; i ++)
scanf("%lf%lf",x+i,y+i); for (i = ;i < n; i ++)
{
for (j = i+; j <= n; j ++)
{
double xx = x[i]-x[j];
double yy = y[i]-y[j];
p[j][i] = p[i][j] = (double)sqrt(xx*xx+yy*yy);
}
}
dijkstra();
printf("Scenario #%d\n",f ++);
//printf("Frog Distance = %.3lf\n",dis[2]); //不知道为什么这种输出一直WA 下面的AC
cout<<fixed<<setprecision()<<"Frog Distance = "<<dis[]<<endl; //setprecision需要加上头文件#include <iomanip>
cout<<endl;
}
}
 

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 最小瓶颈路(变形的最小生成树 prim算法解决(需要很好的理解prim))

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

  6. poj 2253 Frogger (dijkstra最短路)

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

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

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

  8. POJ 2253 Frogger Floyd

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

  9. poj 2253 Frogger (最长路中的最短路)

    链接:poj 2253 题意:给出青蛙A,B和若干石头的坐标,现青蛙A想到青蛙B那,A可通过随意石头到达B, 问从A到B多条路径中的最长边中的最短距离 分析:这题是最短路的变形,曾经求的是路径总长的最 ...

随机推荐

  1. CCocos2Dx 一段遍历子节点的代码

    CCLog("Lein will hide account!CS_FAST_REGISTER_REQ"); <p> CCNode* child1 = (CCNode*) ...

  2. uboot启动 及命令分析(3)

    u-boot命令 先贴一个重要结构,位于uboot/include/command.h,这个结构代表每个uboot命令 struct cmd_tbl_s { char     *name;   /* ...

  3. 大学生成绩管理系统(C语言)

    功能:成绩管理系统包含了学生的全部信息,每个学生是一个记录,包括学号,姓名,性别,班级,各科成绩(语数外). 系统功能: 1.信息录入——录入学生信息: 2.信息输出——显示所有信息: 3.信息查询— ...

  4. SQL学习心得(转)

    http://www.cnblogs.com/lyhabc/p/3732942.html

  5. java面试题之ssh

    1.写出你熟悉的开源框架以及各自的作用(项目中为什么使用SSH) 答:框架:hibernate,spring,struts1/struts2. Hibernate主要用于数据持久化:封装了JDBC操作 ...

  6. java中利用JFrame创建窗体 【转】

    1. 一个简单的swing public class Test(){ public static void main(String[] args){ JFrame frame = new JFrame ...

  7. C++学习 之const

    const在C++中很常用,在编程中也建议多使用const去告诉编译器和其他程序员某个值应该保持不变. const可以用在很多地方: (1)用在classes外部修饰global或namespace作 ...

  8. php的查询数据

    php中 连接数据库,通过表格形式输出,查询数据.全选时,下面的分选项都选中;子选项取消一个时,全选按钮也取消选中. <!DOCTYPE html PUBLIC "-//W3C//DT ...

  9. 2014年3月份第1周51Aspx源码发布详情

    Graphics创建饼图示例源码  2014-3-7 [VS2010]源码描述:这个程序是一个在c#中使用图形类用来创建饼图,此程序是用Graphics 类的DrawPie() 和 FillPie() ...

  10. jsonObject jsonArray jsonTokener jsonStringer,json解析以及http请求获取josn数据并加以解析

    JSON的定义: 一 种轻量级的数据交换格式,具有良好的可读和便于快速编写的特性.业内主流技术为其提供了完整的解决方案(有点类似于正则表达式 ,获得了当今大部分语言的 支持),从而可以在不同平台间进行 ...