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 ...
随机推荐
- TI博客文章-4-20mA电流环路发送器入门
TI博客文章-4-20mA电流环路发送器入门http://bbs.21ic.com/forum.php?mod=viewthread&tid=1610834&fromuid=10995 ...
- Kafka 快速起步
Kafka 快速起步 原创 2017-01-05 杜亦舒 性能与架构 性能与架构 性能与架构 微信号 yogoup 功能介绍 网站性能提升与架构设计 主要内容:1. kafka 安装.启动2. 消息的 ...
- c++ 返回对象的引用要小心
除非能保证返回对象的生命周期足够长. 一定不要返回临时对象的引用.
- 代码覆盖率?coverage
http://www.infoq.com/cn/articles/test-coverage-rate-role 代码覆盖率?coverage http://www.cnblogs.com/cod ...
- [git]git动画教程
git学习资料比较好的有廖雪峰的教程 还有2个动画教程: https://www.zhihu.com/question/38008771 git-scm 廖雪峰-Git教程 git-for ...
- php-fpm配置详解
php-fpm详解 原文链接:http://php-fpm.anight.org/wiki:http://www.php-fpm.com/翻译:http://syre.blogbus.com/logs ...
- ACM_数论_阶乘N!的末尾有几个零 和 末尾有多少个 1 nyoj 954
原文地址 首先阶乘的一个常识要知道就是25!的末尾6位全是0: 前言: <编程之美>这本书,爱不释手! 问题描述: 给定一个整数N,那么N的阶乘N!末尾有多少个0呢?例如:N=10,N!= ...
- Unity5.1 新的网络引擎UNET(四) UNET Remote Actions
孙广东 2015.7.12 网络系统 具有网络中执行操作actions 的方法.这些类型的actions 有时是调用远程过程调用(Remote Procedure Calls). 在网络系统中有两 ...
- ubuntu 安装 qt等软件
1 ubuntu安装qt4 sudo apt-get install qt4-dev-tools qt4-designer qt4-doc qt4-qtconfigqt4-demos qt4-qmak ...
- 排查PHP-FPM占用CPU过高
发现 如何发现的呢?当然是使用top命令,发现系统的load average>3,这说明系统已经处于比较高的负载中. 尝试解决 当我把php-fpm重启后,没过一会儿又开始cpu狂飙!这是什么鬼 ...