【POJ - 2253】Frogger (Floyd算法)
-->Frogger
中文翻译
Descriptions:
Input
先输入一个整数n表示石头数量,当n等于0时结束。
接下来2-n+1行依次给出编号为1到n的石头的坐标xi , yi。
2 <= n <= 200
0 <= xi , yi <= 1000
Output
接下来一行输出"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算法)的更多相关文章
- POJ 2253 Frogger floyd算法
题目:click here 题意: 给出两只青蛙的坐标A.B,和其他的n-2个坐标,任意两坐标间是双向连通的.显然从A到B存在至少一条的通路,每一条通路的元素都是这条通路中前后两个点的距离,这些距离中 ...
- POJ 2253 Frogger Floyd
原题链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
- poj 2253 Frogger dijkstra算法实现
点击打开链接 Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 21653 Accepted: 7042 D ...
- 最短路(Floyd_Warshall) POJ 2253 Frogger
题目传送门 /* 最短路:Floyd算法模板题 */ #include <cstdio> #include <iostream> #include <algorithm& ...
- POJ 2253 Frogger ,poj3660Cow Contest(判断绝对顺序)(最短路,floyed)
POJ 2253 Frogger题目意思就是求所有路径中最大路径中的最小值. #include<iostream> #include<cstdio> #include<s ...
- POJ. 2253 Frogger (Dijkstra )
POJ. 2253 Frogger (Dijkstra ) 题意分析 首先给出n个点的坐标,其中第一个点的坐标为青蛙1的坐标,第二个点的坐标为青蛙2的坐标.给出的n个点,两两双向互通,求出由1到2可行 ...
- POJ 2253 Frogger(dijkstra 最短路
POJ 2253 Frogger Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fion ...
- poj 2253 Frogger 最小瓶颈路(变形的最小生成树 prim算法解决(需要很好的理解prim))
传送门: http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
- POJ 2253 Frogger
题目链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
- POJ 2253 Frogger(Dijkstra变形——最短路径最大权值)
题目链接: http://poj.org/problem?id=2253 Description Freddy Frog is sitting on a stone in the middle of ...
随机推荐
- Android 查看Apk签名方式V1和V2
Android 查看Apk签名方式V1和V2 java -jar apksigner.jar verify -v my.apk -- Verifies Verified using v1 scheme ...
- GIS基础软件及操作(一)
原文 GIS基础软件及操作(一) 练习一.浏览地理数据 使用 ArcGIS浏览地理数据 第1步 启动 ArcMap 启动ArcMap.执行菜单命令:开始>>所有程序>> Ar ...
- SQL Server根据字段查询不出记录
今天写了一条select语句,很奇怪的一件事,我写程序几年了,第一次碰到这个问题,就是数据库里有这个值,你根据这个值查询就是查询不出来这行记录. 所以我想是不是里面有空格,回车什么的,最后果然如此. ...
- 微信小程序把玩(六)模块化
原文:微信小程序把玩(六)模块化 模块化也就是将一些通用的东西抽出来放到一个文件中,通过module.exports去暴露接口.我们在最初新建项目时就有个util.js文件就是被模块化处理时间的 /* ...
- 正则表达式-Csharp
原文:正则表达式-Csharp 学习笔记:正则表达式 一. 正则表达式 正则表达式(Regex)是用来进行文本处理的技术,是语言无关的,在几乎所有语言中都有实现. 一个正则表达式就是由普通的字符及特殊 ...
- 数据库连接池之_c3p0
C3p0 1,手动设置参数 @Test public void demo1(){ Connection connection =null; PreparedStatement preparedStat ...
- libevent for qt的讨论
一直对Qt官方的QtNetwork模块抱有遗憾,Qt自带的网络模块用的是select模型,无法支持高并发的服务器开发.最近在网上看到有个libevent for qt的东西,它直接替换了Qt的sele ...
- acl_cpp 的编译与使用
注:因为现在 acl_cpp 已经合并进 acl 项目中,本文仅是介绍了老版本的 acl_cpp 的编译过程,新版本的介绍及编译请参考:acl 框架库简介. acl_cpp 是基于 acl 为基础开发 ...
- Windows 上静态编译 Libevent 2.0.10 并实现一个简单 HTTP 服务器(图文并茂,还有实例下载)
[文章作者:张宴 本文版本:v1.0 最后修改:2011.03.30 转载请注明原文链接:http://blog.s135.com/libevent_windows/] 本文介绍了如何在 Window ...
- Qt优雅地结束线程(两种方法都是用Mutex锁住bool变量进行修改,然后由bool变量控制耗时动作的退出,即正常退出)
如果一个线程运行完成,就会结束.可很多情况并非这么简单,由于某种特殊原因,当线程还未执行完时,我们就想中止它.不恰当的中止往往会引起一些未知错误.比如:当关闭主界面的时候,很有可能次线程正在运行,这时 ...