POJ 2253 Frogger【最短路变形——路径上最小的最大权】
链接:
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 21206 | Accepted: 6903 |
Description
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
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
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
题意:
算法:
分析:
PS:
code:
floyd:
/*
题意:给出一个无向图,求一条1~2的路径使得路径上的最大边权最小. 分析:floyd变形,将更新距离的过程改为取最大值即可.
*/
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
using namespace std; const double DNF = 2000;
const int maxn = 210; double w[maxn][maxn];
int n; struct Point{
double x,y;
}p[maxn]; double dist(Point a, Point b)
{
return sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
} void floyd()
{
for(int k = 1; k <= n; k++)
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++)
w[i][j] = min(w[i][j], max(w[i][k], w[k][j])); //更新i——j路径上最小的最大边权
} int main()
{
int kcase = 0;
while(scanf("%d", &n) != EOF)
{
if(n == 0) break;
for(int i = 1; i <= n; i++)
{
scanf("%lf%lf", &p[i].x, &p[i].y);
} for(int i = 1; i <= n; i++)
{
w[i][i] = 0;
for(int j = i+1; j <= n; j++)
{
w[i][j] = dist(p[i],p[j]);
w[j][i] = dist(p[i],p[j]);
}
} floyd();
printf("Scenario #%d\n", ++kcase);
printf("Frog Distance = %.3lf\n\n", w[1][2]);
}
}
Dijkstra:
/*
题意:给出一个无向图,求一条1~2的路径使得路径上的最大边权最小. 分析:dijkstra变形,将更新距离的过程改为取最大值即可.
*/
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
using namespace std; const double DNF = 2000;
const int maxn = 210; double w[maxn][maxn];
double d[maxn];
int vis[maxn];
int n;
double ans; struct Point{
double x,y;
}p[maxn]; double dist(Point a, Point b)
{
return sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
} void Dijkstra()
{
for(int i = 1; i <= n; i++) d[i] = DNF;
d[1] = 0;
memset(vis,0,sizeof(vis)); for(int i = 1; i <= n; i++)
{
int x;
double m = DNF;
for(int y = 1; y <= n; y++) if(!vis[y] && d[y] <= m) m = d[x=y];
vis[x] = 1;
if(ans < d[x] && d[x]!= DNF) // ans 是这条路径上的最大权
{
ans = d[x];
}
if(x == 2) return; //走到目的地即可
for(int y = 1; y <= n; y++) if(!vis[y])
d[y] = min(d[y], w[x][y]); //更新未接入的点的dist
} } int main()
{
int kcase = 0;
while(scanf("%d", &n) != EOF)
{
if(n == 0) break;
for(int i = 1; i <= n; i++)
{
scanf("%lf%lf", &p[i].x, &p[i].y);
} for(int i = 1; i <= n; i++)
{
w[i][i] = 0;
for(int j = i+1; j <= n; j++)
{
w[i][j] = dist(p[i],p[j]);
w[j][i] = dist(p[i],p[j]);
}
} ans = 0;
Dijkstra();
printf("Scenario #%d\n", ++kcase);
printf("Frog Distance = %.3lf\n\n", ans);
}
}
POJ 2253 Frogger【最短路变形——路径上最小的最大权】的更多相关文章
- POJ 2253 Frogger ( 最短路变形 || 最小生成树 )
题意 : 给出二维平面上 N 个点,前两个点为起点和终点,问你从起点到终点的所有路径中拥有最短两点间距是多少. 分析 : ① 考虑最小生成树中 Kruskal 算法,在建树的过程中贪心的从最小的边一个 ...
- POJ 2253 Frogger -- 最短路变形
这题的坑点在POJ输出double不能用%.lf而要用%.f...真是神坑. 题意:给出一个无向图,求节点1到2之间的最大边的边权的最小值. 算法:Dijkstra 题目每次选择权值最小的边进行延伸访 ...
- poj 2253 Frogger【最小生成树变形】【kruskal】
Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 30427 Accepted: 9806 Descript ...
- POJ 2253 Frogger (最短路)
Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 28333 Accepted: 9208 Descript ...
- poj 2253 Frogger(最短路 floyd)
题目:http://poj.org/problem?id=2253 题意:给出两只青蛙的坐标A.B,和其他的n-2个坐标,任一两个坐标点间都是双向连通的.显然从A到B存在至少一条的通路,每一条通路的元 ...
- POJ 2253 Frogger(Dijkstra变形——最短路径最大权值)
题目链接: http://poj.org/problem?id=2253 Description Freddy Frog is sitting on a stone in the middle of ...
- POJ 2253 Frogger(dijkstra变形)
http://poj.org/problem?id=2253 题意: 有两只青蛙A和B,现在青蛙A要跳到青蛙B的石头上,中间有许多石头可以让青蛙A弹跳.给出所有石头的坐标点,求出在所有通路中青蛙需要跳 ...
- POJ 2253 Frogger 最短路 难度:0
http://poj.org/problem?id=2253 #include <iostream> #include <queue> #include <cmath&g ...
- [ACM] POJ 2253 Frogger (最短路径变形,每条通路中的最长边的最小值)
Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 24879 Accepted: 8076 Descript ...
随机推荐
- discuz 安装 文件不可写
discuz安装过程中,系统会自动检查环境及文件目录权限,当出现目录不可写: 这个时候只需要用ftp修改文件夹权限就可以了
- 监听用户的后退键,解决部分浏览器回退的bug
监听用户的后退键,解决部分浏览器回退的bug $(document).keydown(function (event) { // 监听backspace键 if (event.keyCode == 8 ...
- laravel的表单验证(下面有些信息未验证,转的)
后台写法: 1.1类的方法 $rules = [ 'email'=>'required|between:4,20', 'password'=>'required|between:6,20' ...
- HashMap实现原理(转)
来自:http://www.cnblogs.com/xwdreamer/archive/2012/05/14/2499339.html 0.参考文献: hash算法 (hashmap 实现原理) Ja ...
- thinkphp验证码出不来
import("ORG.Util.Image"); //图像操作类库 ob_end_clean(); $type = isset($_GET['type'])?$_GET['typ ...
- Spring Aop基础总结
什么是AOP: Aop技术是Spring核心特性之中的一个,定义一个切面.切面上包括一些附加的业务逻辑代码.在程序运行的过程中找到一个切点,把切面放置在此处,程序运行到此处时候会运行切面上的代码.这就 ...
- linux 从百度网盘下载文件的方法
linux 从百度网盘下载文件的方法 发表于2015 年 月 日由shenwang 方法1.wget wget是在Linux下开发的开放源代码的软件,作者是Hrvoje Niksic,后来被移植到包括 ...
- windows下SVN服务的安装与配置
第一步 下载 去svn官网下载一个最新版的svn svn官网下载地址 该链接会跳转到 https://sourceforge.net/projects/win32svn/ 进行下载 第二步 安装 双击 ...
- 第一百五十四节,封装库--JavaScript,表单验证--提交验证
封装库--JavaScript,表单验证--提交验证 将表单的所有必填项,做一个判断函数,填写正确时返回布尔值 最后在提交时,判断每一项是否正确,全部正确才可以 提交 html <div id= ...
- 请写出一段表单提交的HTML代码,表单名称为form1,提交方式为post,提交地址为submit.asp
请写出一段表单提交的HTML代码,表单名称为form1,提交方式为post,提交地址为submit.asp 解答: <form name=”form1” method=”post” action ...