点击打开链接

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. 使自定义事件支持多绑定 js

    <script language="JavaScript" type="text/javascript"> <!-- //定义类class1 ...

  2. Intent的FLAG_ACTIVITY_CLEAR_TOP和FLAG_ACTIVITY_REORDER_TO_FRONT

    Activity的两种启动模式:FLAG_ACTIVITY_CLEAR_TOP和FLAG_ACTIVITY_REORDER_TO_FRONT 1. 如果已经启动了四个Activity:A,B,C和D. ...

  3. VMware Workstation pro 12下载以及序列号

    VMware Workstation 12序列号:下载地址:https://download3.vmware.com/software/wkst/file/VMware-workstation-ful ...

  4. 【性能诊断】七、并发场景的性能分析(windbg案例,线程阻塞)

    简单整理一个测试Demo,抓取dump并验证,步骤如下: Symbol File Path:SRV*C:\Symbols*http://msdl.microsoft.com/download/symb ...

  5. asp.net中virtual和abstract的区别分析

    这篇文章主要介绍了asp.net中virtual和abstract的区别,较为详细的分析了virtual与abstract的概念与具体用法,并以实例的形式予以总结归纳,需要的朋友可以参考下 本文实例分 ...

  6. (转)Edge实现NodeJS与.NET互操作(包括UI界面示例)

    本文转载自:http://blog.csdn.net/kimmking/article/details/42708049 1.  Edge是什么 Edge是一种在进程内实现NodeJS与.NET互操作 ...

  7. (转)手机端html5触屏事件(touch事件)

    本文转载自:http://blog.sina.com.cn/s/blog_51048da70101f0ex.html touchstart:触摸开始的时候触发 touchmove:手指在屏幕上滑动的时 ...

  8. IntelliJ IDEA设置JDK

    File→Project Structure→Project SDK→New   来自为知笔记(Wiz)

  9. 启动Memcache,出现memcached: error while loading shared libraries: libevent-1.4.so.1: cannot open shared

      1.有可能是装了多个 libevent而导致memcache无法识别哪一个,解决方法就是卸载掉一个libevent 2.只安装了一个libevent,但是也报这个错,解决方法 32位系统下:ln ...

  10. c#处理3种json数据的实例

    网络中数据传输经常是xml或者json,现在做的一个项目之前调其他系统接口都是返回的xml格式,刚刚遇到一个返回json格式数据的接口,通过例子由易到难总结一下处理过程,希望能帮到和我一样开始不会的朋 ...