链接:



Frogger
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 21206   Accepted: 6903

Description

Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fiona Frog who is sitting on another stone. He plans to visit her, but since the water is dirty and full of tourists' sunscreen, he wants to avoid swimming and instead reach her
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

The input will contain one or more test cases. The first line of each test case will contain the number of stones n (2<=n<=200). The next n lines each contain two integers xi,yi (0 <= xi,yi <= 1000) representing the coordinates of stone #i. Stone #1 is Freddy's
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

For each test case, print a line saying "Scenario #x" and a line saying "Frog Distance = y" where x is replaced by the test case number (they are numbered from 1) and y is replaced by the appropriate real number, printed to three decimals. Put a blank line
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




题意:


       给出一个无向图,求一条1~2的路径使得路径上的最大边权最小.

算法:

floyd 变形或者 Dijkstra 变形都可以

分析:

        floyd变形,将更新距离的过程改为取最大值即可.
        w[i][j] = min(w[i][j], max(w[i][k], w[k][j]))


PS:

    这道题不像其它的最短路,是求总路径最小,而是不管总路径,只要保证路径上的最大边权在所有可以走的路径中最小就可以了所以要遍历每一条路径了Orz 如果用 Dijkstra 写有点像 Prim

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【最短路变形——路径上最小的最大权】的更多相关文章

  1. POJ 2253 Frogger ( 最短路变形 || 最小生成树 )

    题意 : 给出二维平面上 N 个点,前两个点为起点和终点,问你从起点到终点的所有路径中拥有最短两点间距是多少. 分析 : ① 考虑最小生成树中 Kruskal 算法,在建树的过程中贪心的从最小的边一个 ...

  2. POJ 2253 Frogger -- 最短路变形

    这题的坑点在POJ输出double不能用%.lf而要用%.f...真是神坑. 题意:给出一个无向图,求节点1到2之间的最大边的边权的最小值. 算法:Dijkstra 题目每次选择权值最小的边进行延伸访 ...

  3. poj 2253 Frogger【最小生成树变形】【kruskal】

    Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 30427   Accepted: 9806 Descript ...

  4. POJ 2253 Frogger (最短路)

    Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 28333   Accepted: 9208 Descript ...

  5. poj 2253 Frogger(最短路 floyd)

    题目:http://poj.org/problem?id=2253 题意:给出两只青蛙的坐标A.B,和其他的n-2个坐标,任一两个坐标点间都是双向连通的.显然从A到B存在至少一条的通路,每一条通路的元 ...

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

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

  7. POJ 2253 Frogger(dijkstra变形)

    http://poj.org/problem?id=2253 题意: 有两只青蛙A和B,现在青蛙A要跳到青蛙B的石头上,中间有许多石头可以让青蛙A弹跳.给出所有石头的坐标点,求出在所有通路中青蛙需要跳 ...

  8. POJ 2253 Frogger 最短路 难度:0

    http://poj.org/problem?id=2253 #include <iostream> #include <queue> #include <cmath&g ...

  9. [ACM] POJ 2253 Frogger (最短路径变形,每条通路中的最长边的最小值)

    Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 24879   Accepted: 8076 Descript ...

随机推荐

  1. TI博客文章-4-20mA电流环路发送器入门

    TI博客文章-4-20mA电流环路发送器入门http://bbs.21ic.com/forum.php?mod=viewthread&tid=1610834&fromuid=10995 ...

  2. Kafka 快速起步

    Kafka 快速起步 原创 2017-01-05 杜亦舒 性能与架构 性能与架构 性能与架构 微信号 yogoup 功能介绍 网站性能提升与架构设计 主要内容:1. kafka 安装.启动2. 消息的 ...

  3. c++ 返回对象的引用要小心

    除非能保证返回对象的生命周期足够长. 一定不要返回临时对象的引用.

  4. 代码覆盖率?coverage

    http://www.infoq.com/cn/articles/test-coverage-rate-role 代码覆盖率?coverage   http://www.cnblogs.com/cod ...

  5. [git]git动画教程

    git学习资料比较好的有廖雪峰的教程 还有2个动画教程: https://www.zhihu.com/question/38008771  git-scm  廖雪峰-Git教程  git-for ...

  6. php-fpm配置详解

    php-fpm详解 原文链接:http://php-fpm.anight.org/wiki:http://www.php-fpm.com/翻译:http://syre.blogbus.com/logs ...

  7. ACM_数论_阶乘N!的末尾有几个零 和 末尾有多少个 1 nyoj 954

    原文地址 首先阶乘的一个常识要知道就是25!的末尾6位全是0: 前言: <编程之美>这本书,爱不释手! 问题描述: 给定一个整数N,那么N的阶乘N!末尾有多少个0呢?例如:N=10,N!= ...

  8. Unity5.1 新的网络引擎UNET(四) UNET Remote Actions

    孙广东   2015.7.12 网络系统 具有网络中执行操作actions 的方法.这些类型的actions 有时是调用远程过程调用(Remote Procedure Calls). 在网络系统中有两 ...

  9. ubuntu 安装 qt等软件

    1 ubuntu安装qt4 sudo apt-get install qt4-dev-tools qt4-designer qt4-doc qt4-qtconfigqt4-demos qt4-qmak ...

  10. 排查PHP-FPM占用CPU过高

    发现 如何发现的呢?当然是使用top命令,发现系统的load average>3,这说明系统已经处于比较高的负载中. 尝试解决 当我把php-fpm重启后,没过一会儿又开始cpu狂飙!这是什么鬼 ...