Frogger
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 25773   Accepted: 8374

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

 
题目大意:有两只青蛙和若干块石头,其中一只青蛙想去拜访另一只青蛙,现在已知这些东西的坐标,两只青蛙坐标分别是第一个和第二个坐标,并且这只青蛙可以借助任意石头的跳跃,而两只青蛙之间有若干通路,问两只的所有通路上的最大边,然后在通过这些最大边来找最短路。
从起点到终点会有很多路径,每条路径上的边有一个最大值,求这些最大值中的最小值。
也就是更新的边要保持最大边。
特别注意:这里我也不是很懂的地方,在最后输出的时候用%.3lf就是死命的wa,而改成%.3f就轻松ac了,其实不过在poj上是可以过得了,如果过不了再改也是可以的了,我是在专题里面一直wa,表示很无奈~
 
不多说了,看代码~
 #include <stdio.h>
#include <math.h>
const int INF=;
double map[][],node[],Min;
int n,vis[]; double Max(double a,double b)
{
return a>b?a:b;
} void dijkstra()
{
int i,j,k,m;
for (i=; i<n; i++)
{
node[i]=map[][i];
vis[i]=;
}
vis[]=;
for (k=; k<n; k++)
{
Min=INF;
m=-;
for (i=; i<n; i++)
if (!vis[i])
{
if (Min>node[i])
{
Min=node[i];
m=i;
}
}
if (m==-)
break;
vis[m]=;
//tm=m;
for (i=; i<n; i++)
{
if (!vis[i]&&Max(node[m],map[m][i])<node[i])
node[i]=Max(node[m],map[m][i]); }
}
} int main ()
{
double a[],b[];
int count=,i,j;
while (scanf("%d",&n),n)
{
for (i=; i<n; i++)
{
scanf("%lf%lf",&a[i],&b[i]);
}
for (i=; i<n; i++)
{
for (j=; j<n; j++)
{
map[i][j]=map[j][i]=(a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j]); }
}
dijkstra();
printf("Scenario #%d\n", ++count);
printf("Frog Distance = %.3f\n\n", sqrt(node[]));
}
return ;
}
 
 

poj 2253 Frogger (dijkstra最短路)的更多相关文章

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

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

  2. POJ - 2253 Frogger(最短路Dijkstra or flod)

    题意:要从起点的石头跳到终点的石头,设The frog distance为从起点到终点的某一路径中两点间距离的最大值,问在从起点到终点的所有路径中The frog distance的最小值为多少. 分 ...

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

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

  4. POJ 2253 Frogger【最短路变形——路径上最小的最大权】

    链接: http://poj.org/problem?id=2253 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...

  5. poj 2253 Frogger dijkstra算法实现

    点击打开链接 Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 21653   Accepted: 7042 D ...

  6. poj 2253 Frogger (最短路变种,连通图的最长边)

    题目 这里的dijsktra的变种代码是我看着自己打的,终于把代码和做法思路联系上了,也就是理解了算法——看来手跟着画一遍真的有助于理解. #define _CRT_SECURE_NO_WARNING ...

  7. POJ 2253 Frogger【最短路变形/最小生成树的最大权/最小瓶颈树/A到B多条路径中的最小的最长边】

    Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fiona Frog who is sit ...

  8. POJ 2253 Frogger(最短路&Floyd)题解

    题意:想给你公青蛙位置,再给你母青蛙位置,然后给你剩余位置,问你怎么走,公青蛙全力跳的的最远距离最小. 思路:这里不是求最短路径,而是要你找一条路,青蛙走这条路时,对他跳远要求最低.这个思想还是挺好迁 ...

  9. POJ 2253 Frogger(dijkstra 最短路

    POJ 2253 Frogger Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fion ...

  10. POJ. 2253 Frogger (Dijkstra )

    POJ. 2253 Frogger (Dijkstra ) 题意分析 首先给出n个点的坐标,其中第一个点的坐标为青蛙1的坐标,第二个点的坐标为青蛙2的坐标.给出的n个点,两两双向互通,求出由1到2可行 ...

随机推荐

  1. PAT 1052 卖个萌

    https://pintia.cn/problem-sets/994805260223102976/problems/994805273883951104 萌萌哒表情符号通常由“手”.“眼”.“口”三 ...

  2. 【bzoj1441】Min 扩展裴蜀定理

    题目描述 给出n个数(A1...An)现求一组整数序列(X1...Xn)使得S=A1*X1+...An*Xn>0,且S的值最小 输入 第一行给出数字N,代表有N个数 下面一行给出N个数 输出 S ...

  3. 【bzoj1579】[Usaco2009 Feb]Revamping Trails 道路升级 分层图最短路

    题目描述 每天,农夫John需要经过一些道路去检查牛棚N里面的牛. 农场上有M(1<=M<=50,000)条双向泥土道路,编号为1..M. 道路i连接牛棚P1_i和P2_i (1 < ...

  4. linux虚拟机磁盘扩展与分区大小调整

    有段时间觉得linux虚拟机上的磁盘不太够用,研究了下其磁盘扩展 1.linux虚拟机磁盘扩展 step1. 先关机在编辑虚拟机中,找到硬盘选项增加空间,进行扩展step2. 进入root fdisk ...

  5. CentOS httpd服务(Apache)

    1.从ISO镜像安装,Apache 服务的软件包名称为 httpd #检查源配置[root@localhost media]# cat /etc/yum.repos.d/CentOS-Media.re ...

  6. 2017 ICPC beijing E - Cats and Fish

    #1631 : Cats and Fish 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 There are many homeless cats in PKU camp ...

  7. Linux相关——关于gdb的checkpoint & breakpoints指令

    1,checkpoint ,,,这个指令简直,,,相见恨晚啊,居然现在才发现,.. 好吧来介绍一下这个指令:checkpoint(检查点) 我们调试程序,常常会出现好不容易发现了错误,却已经跑完那个地 ...

  8. Android APP性能优化(最新总结)

    导语   安卓大军浩浩荡荡,发展已近十个年头,技术优化日异月新,如今Android 8.0 Oreo 都发布了,Android系统性能已经非常流畅了.但是,到了各大厂商手里,改源码自定系统,使得And ...

  9. POJ2689:Prime Distance——题解

    http://poj.org/problem?id=2689 题目大意,给不超过int的l,r,其中r-l+1<=1000000,筛出其中的素数,并且求出相邻素数差值最大和最小的一对. ———— ...

  10. redux connect的浅比较说明

    redux的connect方法是一个高阶组件,对包装的组件会在ShouldComponentUpdate中实现一个默认的浅比较. connect形式如下: connect([mapStateToPro ...