题目链接: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. 使用WBI SAP Adapter 实现IDoc的同步处理(转)

    1. 应用背景 某汽车制造企业(以下称为厂商A)与其仓储系统提供商(以下称为厂商B)需要进行数据交换.汽车厂商A使用SAP系统作ERP管理,所有数据都要进入SAP进行处理,仓储系统提供商使用的是自有的 ...

  2. C# 子窗体点击按钮产生的新子窗体放在父窗体里

    情景展示: 父窗体Form1,左边是按钮,右边是panel(放置子窗体) 父窗体点击按钮,在panel显示第一个子窗体AA, AA有个按钮,点击按钮,是第二个子窗体ZZ, 怎样将AA的子窗体ZZ也显示 ...

  3. iOS9/iOS8界面对比 XCode7

    Xcde7 bate 无需开发这账号(99¥)可以调试程序 目前是测试版 iOS9/iOS8界面对比 (注:左边为iOS8界面,右边为iOS9界面.) 1.新字体 苹果在 iOS9 中使用旧金山字体取 ...

  4. Section 1.4 Mother's Milk

    又是一道怨念已久的题目0 0之前深搜写过广搜写过,怎么就是卡死,我还以为FP坏了重新装了一遍.今天偶尔翻起来,发现广搜忘记inc(head)了…简直哭瞎… 简单的广搜,分类比较多,不过不太要动脑子.至 ...

  5. DotNetBar v12.3.0.3 Fully Cracked

    PS: 博客园的程序出现问题,导致我的博客不能访问(转到登录页),而我自己由于 Cookies 问题,一直可以访问,所以一直未发现该问题. 感谢冰河之刃告知,thx! 更新信息: http://www ...

  6. 2013年8月份第2周51Aspx源码发布详情

    上班族网站(毕设)源码  2013-8-16 [VS2010]源码描述:自己做的毕业设计,上班族网站项目是专门针对上班族群体设计和开发的网站项目.该网站主要涵盖了论坛平台,笑话模块,名言模块,资讯模块 ...

  7. dllimport路径问题

    今天做了个试验,是针对dllimport("XXX.DLL");这样写的时候,系统是如何寻找该dll的. 首先系统会搜寻主应用程序根目录. 其次搜寻操作系统安装目录,一般情况是C: ...

  8. 解决win7资源监视器不能开启

    刚开始时是这样,点击开始监控,无效 需要开始服务即可解决

  9. 如何实现标准TCODE的屏幕增强

    如何实现标准TCODE的屏幕增强(HOWTO:Implement a screen exit to a standard SAP transaction) Introduction SAP provi ...

  10. Java中的blank final

    Java allows the creation of blank finals, which are fields that are declared as final but are not gi ...