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 ...
随机推荐
- SICP 1.23-1.26体会
1.23 代码修改非常easy, 关键是时间. 电脑上算了一下. 100000000下面全是0. 開始还以为代码写错了. 最后没办法, 用1e10 1e11来计算. 发现比 1e11 1e12快1.2 ...
- OpenJudge百炼习题解答(C++)--题4074:积水量
题: 总时间限制: 1000ms 内存限制:65536kB 描写叙述 凹凸不平的地面每当下雨的时候总会积水.如果地面是一维的.每一块宽度都为1,高度是非负整数.那么能够用一个数组来表达一块 ...
- atitit.词法分析原理 词法分析器 (Lexer)
atitit.词法分析原理 词法分析器 (Lexer) 1. 词法分析(英语:lexical analysis)1 2. :实现词法分析程序的常用途径:自动生成,手工生成.[1] 2 2.1. 词法分 ...
- maven添加额外archetype
用Eclipse + m2e 插件新建maven项目时发现archetype太少了,网上搜索如何添加额外的archetype. http://maven.apache.org/archetype/ma ...
- java 容器结构
先来看下层次关系. 如图所示:图中,实线边框的是实现类,折线边框的是抽象类,而点线边框的是接口 Collection(接口)├──List(接口)│ ├──LinkedList(实现类)│ ├ ...
- iptables详细教程:基础、架构、清空规则、追加规则、应用实例(转)
iptables防火墙可以用于创建过滤(filter)与NAT规则.所有Linux发行版都能使用iptables,因此理解如何配置iptables将会帮助你更有效地管理Linux防火墙.如果你是第一次 ...
- makefile之if函数
#if 函数的语法是: #$(if <condition>,<then-part> ) #或 #$(if <condition>,<then-part> ...
- redis 优缺点 使用场景
1. 使用redis有哪些好处? (1) 速度快,因为数据存在内存中,类似于HashMap,HashMap的优势就是查找和操作的时间复杂度都是O(1) (2) 支持丰富数据类型,支持string,li ...
- C#非常规调试场景总结
场景1:类库独立调试. 方法:可以将类库项目修改成控制台程序,然后增加一个静态的main函数的方式来调试 场景2:程序需要连接数据库,本机调试的时候因为权限问题无法连接上数据库,只能 ...
- web.py使用要点
这几天有一个构建restful services的需求,我采用了web.py,之前并没有使用过,但在使用中确实给我带来了很多惊喜.当然,最大的惊喜就是简单,方便.之前开发restful服务的时候,采用 ...