**题意描述
给出一系列的点,前两个点是青蛙的坐标,需要求的是第一个坐标到第二个坐标之间经历的最短距离。
解题思路:
还是Dijkstra算法做题,在数组进行存储的时候通过用数学方法求出知道的两个点之间的坐标求出他们之间的距离,然后存入对应的二维数组具体代码如下:

for(i=1; i<=n; i++)
for(j=1; j<=n; j++)
e[i][j]=e[j][i]=sqrt((x[i]-x[j])(x[i]-x[j])+(y[i]-y[j])(y[i]-y[j]));
另外再求最短距离的时候Dijkstra的核心算法改为

    for(i=1; i<=n; i++){min=inf; for(j=1; j<=n; j++){if(book[j]==0&&min>dis[j]){u=j;min=dis[j];}}book[u]=1;for(v=1; v<=n; v++){if(dis[v]<inf){***if(dis[v]>e[u][v]&&dis[v]>dis[u]){if(dis[u]>e[u][v])dis[v]=dis[u];elsedis[v]=e[u][v];}***}}

英文题目
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
中文题目:

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
弗雷迪·青蛙坐在湖中的一块石头上。突然,他发现菲奥娜·青蛙坐在另一块石头上。他计划去看望她,但由于水很脏,而且有很多游客的防晒霜,所以他想避免游泳,而是跳到她跟前。
不幸的是菲奥娜的石头超出了他的跳跃范围。因此,弗雷迪考虑使用其他石头作为中间停止,并通过几次小跳跃的顺序到达她。
要执行给定的跳跃序列,青蛙的跳跃范围显然必须至少与序列中发生的最长跳跃相同。
因此,两块石头之间的青蛙距离(人类也称之为最小-最大距离)被定义为两块石头之间所有可能路径的最小必要跳跃范围。

你得到了弗雷迪的石头,菲奥娜的石头和湖中所有其他石头的坐标。你的工作是计算弗雷迪和菲奥娜石头之间的青蛙距离。
输入
输入将包含一个或多个测试用例。每个测试用例的第一行将包含石头数量n(2<=n<=200)。下n行各包含两个整数Xi,Yi(0<=Xi,Yi=1000),表示石头的坐标i。石头1是弗莱迪的石头,石头2是菲奥娜的石头,其他的N-2石头是空的。每个测试用例后面都有一个空白行。对于n,输入以零(0)的值终止。
输出
对于每个测试用例,打印一行“Scenario_x”和一行“Frog Distance=y”,其中x替换为测试用例编号(从1开始编号),y替换为适当的实数,打印为三位小数。在每个测试用例之后,甚至在最后一个测试用例之后,都放一个空白行。
AC代码:

#include<stdio.h>
#include<math.h>
#include<string.h>
struct node{double x;double y;
}s[2000];
double dp[2000][2000];
double dis[20000];
int book[20000];
int inf=99999999;
int main()
{int n,m,u,v,w,i,j,k,min,a=0;double p,q;while(scanf("%d", &n),n!=0){memset(book,0,sizeof(book));for(i=1; i<=n; i++)scanf("%lf %lf", &s[i].x,&s[i].y);for(i=1; i<=n; i++){for(j=1; j<=n; j++){p=s[i].x-s[j].x;q=s[i].y-s[j].y;dp[i][j]=dp[j][i]=sqrt(p*p+q*q);}}for(i=1; i<=n; i++)dis[i]=dp[1][i];book[1]=1;for(i=1; i<n; i++){min=inf;for(j=1; j<=n; j++){if(book[j]==0&&dis[j]<min){min=dis[j];k=j;}}book[k]=1;for(v=1; v<=n; v++){if(dp[k][v]<inf){if(dis[v]>dis[k]&&dis[v]>dp[k][v])dis[v]=(dis[k]>dp[u][v])?dis[k]:dp[u][v];}}}printf("Scenario #%d\nFrog Distance = %.3f\n\n", ++a,dis[2]);}return 0;
}

poj-2253 Frogger(最短路)相关推荐

  1. POJ 2253 Frogger(最短路 Floyd)

    Frogger 大意: 给出两个青蛙的坐标和其他n-2个石头的坐标,任一两个坐标点间都是双向连通的.现在要求求出所有通路的最大距离,并把这些最大距离作比较,把最小的一个最大距离作为青蛙的最小跳远距离. ...

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

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

  3. POJ 2253 Frogger(floyd dijkstra spfa)

    题目链接:http://poj.org/problem?id=2253 题目: 弗雷迪青蛙正坐在湖中央的一块石头上. 突然,他注意到正坐在另一块石头上的菲奥娜青蛙. 他打算去看望她,但由于水很脏,游客 ...

  4. POJ 2253 Frogger (求某两点之间所有路径中最大边的最小值)

    题意:有两只青蛙,a在第一个石头,b在第二个石头,a要到b那里去,每种a到b的路径中都有最大边,求所有这些最大边的最小值. 思路:将所有边长存起来,排好序后,二分枚举答案. 时间复杂度比较高,344m ...

  5. B - Frogger POJ - 2253

    B - Frogger POJ - 2253 题意: 从 1 号点出发,找每一条能够到达 2 号点的路径,每条路径的答案是该路径中相邻两点之间距离的最大值,求这些答案中的最小值. 思路: 感觉不是最短 ...

  6. [kuangbin带你飞]专题四 最短路练习 B( POJ 2253) Frogger(spfa)

    B - Frogger(spfa) 题目链接:https://vjudge.net/contest/66569#problem/B 题目: Freddy Frog is sitting on a st ...

  7. poj 2253 最短路变形——最大边的最小值

    文章目录 本题:最短路变形--最大边的最小值 最短路变形--最小边的最大值 本题:最短路变形--最大边的最小值 题意: 给出两只青蛙.以及其他石头的坐标,需要求出可以到达另一只青蛙的所有路径中,青蛙跳 ...

  8. 【POJ - 2253】Frogger(floyd,或 部分瓶颈生成树的最大边)

    题干: 湖中有n块石头,编号从1到n,有两只青蛙,Bob在1号石头上,Alice在2号石头上,Bob想去看望Alice,但由于水很脏,他想避免游泳,于是跳着去找她.但是Alice的石头超出了他的跳跃范 ...

  9. POJ 3255 Roadblocks 次短路

    和Dijksta求最短路一样,只是要维护两个数组:最短路d1,次短路d2.然后更新的时候注意细节. //#pragma comment(linker, "/STACK:1024000000, ...

  10. POJ - 1847 Tram(最短路)

    题目链接:点击查看 题目大意:火车从起点开到终点,轨道上有很多岔路口,每个岔路口都有很多方向(火车能够选择任意一个方向行驶),但是默认 的是第一个方向,如果要选择其他的方向需要增加一次切换的操作,问最 ...

最新文章

  1. 网站优化也逃不过“细节决定成败”定律
  2. oracle 存储过程写文件,Oracle写本地文件
  3. oracle 创建一揽子协议,Oracle PO - 模块一揽子采购协议小结
  4. 比python好_这就是为什么Python比R更好的原因
  5. 前后端交互之封装Ajax+SpringMVC源码分析
  6. mac安装adb工具
  7. php require失败,关于php:致命错误:require_once()[function.require]:要求打开失败
  8. 如何删除微软拼音输入法2003
  9. 计算机 word 节是什么,Word分节符的含义和使用方法详解-word技巧-电脑技巧收藏家...
  10. CF卡 本地磁盘模式转换
  11. 艺展中心七夕游园雅集,梦回长安品古韵
  12. 微信小程序:页面有内容却不显示原因
  13. Android Wifi连接 (PEAP)
  14. PDM转换成Word文档或者XML文档
  15. 新纪元财务、进销存一体化软件 v4.0 官方
  16. 用Oracle PL/SQL 编程实现小数转分数的方法
  17. TCP笔记之阅读《TCP/IP协议卷一》
  18. 4~20mA电流输出芯片XTR111完整电路
  19. 2022爱分析・采购数字化厂商全景报告 | 爱分析报告
  20. Boost.Asio 笔记

热门文章

  1. 基于Java毕业设计药品管理系统演示录像 2021源码+系统+mysql+lw文档+部署软件
  2. 【华为机试真题Java】英文输入法
  3. html5 canvas 画阿迪达斯logo,canvas绘图画出了的美团LOGO
  4. js中的图片指定切换效果
  5. 为什么两表关联查询时唯一索引没有生效
  6. umi(react)项目中引入monaco-editor
  7. CISP-PTE考前练习-文件包含
  8. java web 订餐系统_javaWeb应用 ssm架构 三方外卖系统
  9. 上海翊科完成B轮融资,启明创投独家投资
  10. uni-app H5页面打开地图组件 [system] Map key not configured