-->Frogger

中文翻译

Descriptions:

湖中有n块石头,编号从1到n,有两只青蛙,Bob在1号石头上,Alice在2号石头上,Bob想去看望Alice,但由于水很脏,他想避免游泳,于是跳着去找她。但是Alice的石头超出了他的跳跃范围。因此,Bob使用其他石头作为中间站,通过一系列的小跳跃到达她。两块石头之间的青蛙距离被定义为两块石头之间所有可能路径上的最小必要跳跃距离,某条路径的必要跳跃距离即这条路径中单次跳跃的最远跳跃距离。你的工作是计算Alice和Bob石头之间的青蛙距离。

Input

多实例输入 
先输入一个整数n表示石头数量,当n等于0时结束。
接下来2-n+1行依次给出编号为1到n的石头的坐标xi , yi。
2 <= n <= 200 
0 <= xi , yi <= 1000


Output

先输出"Scenario #x", x代表样例序号。
接下来一行输出"Frog Distance = y", y代表你得到的答案。 
每个样例后输出一个空行。
(ps:wa有可能是精度问题,g++不对可以用c++尝试,都不对就是代码问题)


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

题目链接:
https://vjudge.net/problem/POJ-2253

我也是第一次做这样的题,用到一个算法

用Floyd算法求出两两最短路,再求出从每个点开始的最长路,最后从这n个最长路中求出最小的那个即为所求。

Floyd算法

https://www.cnblogs.com/sky-stars/p/11204139.html

AC代码:

#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x,y) memset(x,y,sizeof(x))
#define Maxn 205
using namespace std;
struct node
{
double x,y;
};
node points[Maxn];
double path[Maxn][Maxn];//两点间的权值
int cases=;
int n;
//Floyd算法
void floyd()
{
for(int k=; k<=n; k++)
//主要针对由i到j的松弛,最终任意两点间的权值都会被分别松弛为最大跳的最小(但每个两点的最小不一定相同)
for(int i=; i<=n-; i++)
for(int j=i+; j<=n; j++)
//当边ik,kj的权值都小于ij时,则走i->k->j路线,否则走i->j路线
if(path[i][k]<path[i][j]&&path[k][j]<path[i][j])
//当走i->k->j路线时,选择max{ik,kj},只有选择最大跳才能保证连通
if(path[i][k]<path[k][j])
path[i][j]=path[j][i]=path[k][j];
else
path[i][j]=path[j][i]=path[i][k];
}
int main()
{
while(cin>>n,n)
{
for(int i=; i<=n; i++)
cin>>points[i].x>>points[i].y;
for(int i=; i<=n-; i++)
for(int j=i+; j<=n; j++)
{
//两点间的距离
double tx=points[j].x-points[i].x;
double ty=points[j].y-points[i].y;
path[i][j]=path[j][i]=sqrt(tx*tx+ty*ty);//双向性
} floyd();
cout<<"Scenario #"<<cases++<<endl;
printf("Frog Distance = %.3lf\n\n",path[][]);
}
}

【POJ - 2253】Frogger (Floyd算法)的更多相关文章

  1. POJ 2253 Frogger floyd算法

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

  2. POJ 2253 Frogger Floyd

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

  3. poj 2253 Frogger dijkstra算法实现

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

  4. 最短路(Floyd_Warshall) POJ 2253 Frogger

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

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

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

  6. POJ. 2253 Frogger (Dijkstra )

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

  7. POJ 2253 Frogger(dijkstra 最短路

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

  8. poj 2253 Frogger 最小瓶颈路(变形的最小生成树 prim算法解决(需要很好的理解prim))

    传送门: http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissi ...

  9. POJ 2253 Frogger

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

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

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

随机推荐

  1. Qt浮动按钮的实现(使用窗口背景透明、实现只显示浮动按钮的目的)

    Qt浮动按钮的实现 效果如下: 图3 估计很多做Qt有一定经验的朋友会觉得这个效果不难,但是这是一个需求奇葩的实际业务中做出的效果.笔者会想讲下客户的需求和整体框架的矛盾. 整个项目主要是由Qt搭建的 ...

  2. websocket协议学习

    一 实验代码 client.html websocket_server.go package main import ( "crypto/sha1" "encoding/ ...

  3. 在DELPHI中*.wav 文件怎么加到资源文件中

    比较“流行”的说法是:“16位的Delphi   1.0和32位的Delphi2.0.3.0都提供了资源         编译工具,其中   Delphi   1.0的资源编译器叫BRCC.EXE,D ...

  4. CLSRSC-400: A system reboot is required to continue installing.

    I try to install oracle database 12c RAC on the RedHat 7.3,when I execute the script '/u01/app/12.2. ...

  5. Unity 3d新手上路

    作为一位unity新手,初学遇到了不少坑,而且不知道怎么找,发觉网上关于unity的文档好少,还是我暂时没找到. 现在说说void OnTriggerEnter(Collider e),这个函数是我加 ...

  6. 设置Windows服务的访问权限

    作者:beyond 默认情况下,只有管理员组成员.LocalSystem和Power Users组成员帐户才有权启动.停止服务.为了让普通用户也可以控制该服务,我们可以手动设置其访问权限.可能有些初学 ...

  7. mysql-5.7.24-winx64安装与Navicat_for_MySQL_10.1.7注册码

    mysql安装图解:https://blog.csdn.net/qq_38455201/article/details/83419450 Navicat注册码名:组织:注册码:均为NAVN-LNXG- ...

  8. wince kill 进程

    http://www.cnblogs.com/fujinliang/archive/2012/09/13/2684165.html 原文地址 http://www.2cto.com/kf/201504 ...

  9. java小数保留位数四舍五入

    方法一:四舍五入 double f = 111231.5585; BigDecimal b = new BigDecimal(f); double f1 = b.setScale(2, Roundin ...

  10. Ubuntu 16.04.3启动MySQL报错

    今天安装mysql,连接MySQL时报错mysql: [Warning] Using a password on the command line interface can be insecure. ...