链接:



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. PowerShell---Operators 介绍

    1.Arithmetic operators(算术运算符) 算术运算符包括加.减.乘.除.取模 此外,加法运算符 (+) 和乘法运算符 (*) 还可对字符串.数组和哈希表进行运算.加法运算符将输入连接 ...

  2. Navicat Premium 快捷键

    1.ctrl+q 打开查询窗口2.ctrl+/ 注释sql语句3.ctrl+shift +/ 解除注释4.ctrl+r 运行查询窗口的sql语句5.ctrl+shift+r 只运行选中的sql语句6. ...

  3. C语言 文件操作

    /** *@author cody *@date 2014-08-09 *@description copy text file * FILE *fopen(filename,openmode) * ...

  4. IIS8.5设置 MVC HTTP 错误 404.0 - Not Found

    0. 确认 设置IIS的“ISAPI和CGI限制”中的“ASP.NET v4.0.0.30319”为允许 1. 解决方案 <system.webServer>    <modules ...

  5. 点滴积累【C#】---C#实现上传word将路径保存到数据库,文件保存到服务器。并且按照名称读取服务器的word

    效果: 1. . . 数据库: 思路: 上传:先获取word物理地址,然后根据文件的类型判断,然后再保存到相应的文件夹下,再把路径插入到数据库中. 读取:首先根据输入的文件名字在数据库中查找出来文件的 ...

  6. WebSocket遇到的一些问题

    一 .Nginx配置websocket   为了解决Nginx转发不能进行websocket通信问题 将nginx配置文件添加如下内容:   map $http_upgrade $connection ...

  7. ArgumentException: Getting control x's position in a group with only x controls when doing KeyDown Aborting解决方法

    标题有点长,做Editor工具时遇到的问题.最后解决了,总结下 有可能你在界面中用了键盘事件或者其他事件,导致这个报错.官方论坛有个解释比较给力LINK 我在渲染Layout和Repaint的时候加上 ...

  8. 使用SQLite

    SQLite是一种嵌入式数据库,它的数据库就是一个文件.由于SQLite本身是C写的,而且体积很小,所以,经常被集成到各种应用程序中,甚至在iOS和Android的App中都可以集成. Python就 ...

  9. QWidget::setLayout: Attempting to set QLayout "" on MainWindow "", which already has a layout

    http://blog.csdn.net/zhuyingqingfen/article/details/6562246 如题,出现这个的原因是,如果你的窗口继承的是QMainwindow,需要设置 s ...

  10. Linux之实用GDB技巧

    一.引言 在Linux下开发,肯定少不了与gdb打交道,而gdb的命令又非常多,有些是不常用的但是特殊情况下却是必须的,因此记录在此,以便翻阅 二.基本命令 前面是命令全名,在不混淆的情况下,可以简写 ...