点击打开链接

Frogger
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 21653   Accepted: 7042

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

题目大意就是说一个青蛙想从一个石头跳到另一个石头上,这两个石头之间有很多其他的石头,所以青蛙有很多路径可以选择,题目要我们求出跳跃范围最少多远,青蛙才能找到一条跳过去的路,很明显,这个距离必须是这条路径上最长的。

使用Dijkstra算法,虽然这个算法是求最短路径的,而这个题目跟最短路径没有半毛钱关系,但是我们只需要把Dijkstra算法中松弛的条件改一下,就可以了,原来的dij算法中只有当前距离小于已经记录的距离的时候,会执行松弛操作,现在把这个距离改成从起点到当前点的最短跳跃距离,那么当这个最短跳跃距离变小的时候,就松弛一下

#include<stdio.h>
#include<math.h>
#include<string.h>
int n, i = 1;
double map[202][2];
double dis[202][202];
double d[202];
void dij()
{
bool flag[202] = {0};
int j, k;
int curr = 1;
for(j = 1; j <= n; j++)
{
d[j] = 0x7fffffff;
}
d[1] = 0;
for(j = 1; j <= n; j++)
{
int mark = -1;
double mindis = 0x7fffffff;
for(k = 1; k <= n; k++)
{
if(flag[k] == 0 && d[k] < mindis)
{
mindis = d[k];
mark = k;
}
}
flag[mark] = 1;
for(k = 1; k <= n; k++)
{
d[k] = (d[mark] > dis[mark][k] ? d[mark] : dis[mark][k]) > d[k] ? d[k] : (d[mark] > dis[mark][k] ? d[mark] : dis[mark][k]);
}
}
}
int main()
{ double x, y;
while(scanf("%d", &n) != EOF)
{
if(n == 0)
break;
int j, k;
for(j = 1; j <= n; j++)
{
scanf("%lf %lf", &x, &y);
map[j][0] = x;
map[j][1] = y;
for(k = 1; k < j; k++)
{
double temp;
temp = sqrt((x - map[k][0]) * (x - map[k][0]) + (y - map[k][1]) * (y - map[k][1]));
dis[j][k] = temp;
dis[k][j] = temp;
}
}
dij();
printf("Scenario #%d\nFrog Distance = %.3lf\n\n", i, d[2]);
i++;
}
return 0;
}

poj 2253 Frogger dijkstra算法实现的更多相关文章

  1. POJ 2253 - Frogger - [dijkstra求最短路]

    Time Limit: 1000MS Memory Limit: 65536K Description Freddy Frog is sitting on a stone in the middle ...

  2. POJ 2253 Frogger floyd算法

    题目:click here 题意: 给出两只青蛙的坐标A.B,和其他的n-2个坐标,任意两坐标间是双向连通的.显然从A到B存在至少一条的通路,每一条通路的元素都是这条通路中前后两个点的距离,这些距离中 ...

  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. 最短路(Floyd_Warshall) POJ 2253 Frogger

    题目传送门 /* 最短路:Floyd算法模板题 */ #include <cstdio> #include <iostream> #include <algorithm& ...

  6. POJ 2253 Frogger ,poj3660Cow Contest(判断绝对顺序)(最短路,floyed)

    POJ 2253 Frogger题目意思就是求所有路径中最大路径中的最小值. #include<iostream> #include<cstdio> #include<s ...

  7. POJ 2253 Frogger(Dijkstra变形——最短路径最大权值)

    题目链接: http://poj.org/problem?id=2253 Description Freddy Frog is sitting on a stone in the middle of ...

  8. POJ 2253 Frogger(dijkstra变形)

    http://poj.org/problem?id=2253 题意: 有两只青蛙A和B,现在青蛙A要跳到青蛙B的石头上,中间有许多石头可以让青蛙A弹跳.给出所有石头的坐标点,求出在所有通路中青蛙需要跳 ...

  9. poj 2253 Frogger (dijkstra最短路)

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

随机推荐

  1. CA接口测试类

    package com.creditharmony.adapter.testCase.ca; import org.junit.Test; import com.alibaba.druid.util. ...

  2. 将war文件解压到指定目录

    问:如何将.war文件解压到指定目录? 答:jar命令没有这样的选项. eg:将abc.war解压到当前文件夹? 答:进入目标文件即abc.war文件所在的文件夹,按住shift键并在该文件夹空白处点 ...

  3. Python列表,元组,字典,序列,引用

    1.列表 # Filename: using_list.py # This is my shopping list shoplist=["apple", "mango&q ...

  4. flash读取XML节点内容以及节点属性

    原文地址:http://hi.baidu.com/yqzdm/item/f95fd9d24679d916d90e44c9 一.xml的写法: 这里的xml只是在有限范围内的了解,限于写一些简单的用于f ...

  5. ARM Linux从Bootloader、kernel到filesystem启动流程

    转自:http://www.veryarm.com/1491.html ARM Linux启动流程大致为:bootloader ---->kernel---->root filesyste ...

  6. 黄聪:Wordpress 模版技术手册 - WordPress Theme Technical manuals

    WordPress基本模板文件 一套完整的WordPress模板应至少具有如下文件: style.css : CSS(样式表)文件 index.php : 主页模板 archive.php : Arc ...

  7. 黄聪:wordpress如何使用wp_rewrite实现自定义伪静态,非301重定向。

    今天,想通过wordpress实现 http://hcsem.com/a?h-1 伪静态为 http://hcsem.com/a-1.html 找了很多资料,终于搞定. 只需要在functions.p ...

  8. RMAN_Oracle RMAN的常用Configure配置

    2014-12-09 Created By BaoXinjian

  9. DBA_Oracle Erp中某个Form需进行升级Patch详解(案例)

    2014-06-21 Created By BaoXinjian

  10. Codeforces Round #373 (Div. 2)A B

    Codeforces Round #373 (Div. 2) A. Vitya in the Countryside 这回做的好差啊,a想不到被hack的数据,b又没有想到正确的思维 = = [题目链 ...