题目链接:http://poj.org/problem?id=2253

Frogger
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 49409   Accepted: 15729

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.最短路的变形:把dis[i]从原来的记录最短距离 变为 记录不同路径上最大边权中的最小值。
2.利用dijkstra算法时,每次松弛都是选取dis的最小值。
 
 
 
代码如下:
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <set>
#define rep(i,a,n) for(int (i) = a; (i)<=(n); (i)++)
#define ms(a,b) memset((a),(b),sizeof((a)))
using namespace std;
typedef long long LL;
const double EPS = 1e-;
const int INF = 2e9;
const LL LNF = 9e18;
const int MOD = 1e9+;
const int MAXN = 1e3+; int n; struct edge
{
double w;
int to, next;
}edge[MAXN*MAXN];
int cnt, head[MAXN]; void addedge(int u, int v, double w)
{
edge[cnt].to = v;
edge[cnt].w = w;
edge[cnt].next = head[u];
head[u] = cnt++;
} void init()
{
cnt = ;
memset(head, -, sizeof(head));
} double dis[MAXN];
bool vis[MAXN];
void dijkstra(int st)
{
memset(vis, , sizeof(vis));
for(int i = ; i<=n; i++)
dis[i] = (i==st?:INF); for(int i = ; i<=n; i++)
{
int k;
double minn = INF;
for(int j = ; j<=n; j++)
if(!vis[j] && dis[j]<minn)
minn = dis[k=j]; vis[k] = ;
for(int j = head[k]; j!=-; j = edge[j].next) //dis[i]为经过i点的路径中边权最大值的最小值。
if(!vis[edge[j].to])
dis[edge[j].to] = min(dis[edge[j].to], max(dis[k], edge[j].w) );
}
} int x[MAXN], y[MAXN];
int main()
{
int kase = ;
while(scanf("%d", &n) && n)
{
init();
for(int i = ; i<=n; i++)
scanf("%d%d", &x[i], &y[i]);
for(int i = ; i<=n; i++)
for(int j = ; j<=n; j++)
addedge(i, j, sqrt( (x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])) ); dijkstra();
printf("Scenario #%d\n", ++kase);
printf("Frog Distance = %.3f\n\n", dis[]);
}
}

POJ2253 Frogger —— 最短路变形的更多相关文章

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

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

  2. B - Frogger 最短路变形('最长路'求'最短路','最短路'求'最长路')

    http://poj.org/problem?id=2253 题目大意: 有一只可怜没人爱的小青蛙,打算去找他的女神青蛙姐姐,但是池塘水路不能走,所以只能通过蹦跶的形式到达目的地,问你从小青蛙到青蛙姐 ...

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

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

  4. POJ2253 frogger 最短路 floyd

    #include<iostream>#include<algorithm>#include<stdio.h>#include<string.h>#inc ...

  5. POJ-2253.Frogger.(求每条路径中最大值的最小值,最短路变形)

    做到了这个题,感觉网上的博客是真的水,只有kuangbin大神一句话就点醒了我,所以我写这篇博客是为了让最短路的入门者尽快脱坑...... 本题思路:本题是最短路的变形,要求出最短路中的最大跳跃距离, ...

  6. POJ 3635 - Full Tank? - [最短路变形][手写二叉堆优化Dijkstra][配对堆优化Dijkstra]

    题目链接:http://poj.org/problem?id=3635 题意题解等均参考:POJ 3635 - Full Tank? - [最短路变形][优先队列优化Dijkstra]. 一些口胡: ...

  7. POJ 3635 - Full Tank? - [最短路变形][优先队列优化Dijkstra]

    题目链接:http://poj.org/problem?id=3635 Description After going through the receipts from your car trip ...

  8. POJ-1797Heavy Transportation,最短路变形,用dijkstra稍加修改就可以了;

    Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K          Description Background  Hugo ...

  9. HDOJ find the safest road 1596【最短路变形】

    find the safest road Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

随机推荐

  1. EC++学习笔记(一) 习惯c++

    条款01:c++多范式编程语言 条款02:尽量以 const, enum, inline 替换#define 1. 提供类型安全检查 2. 去除函数调用开销 3. 避免宏的二义性 const doub ...

  2. COdevs 1074 食物链

    1074 食物链 2001年NOI全国竞赛  时间限制: 3 s 空间限制: 64000 KB 题目等级 : 钻石 Diamond 题目描述 Description 动物王国中有三类动物 A,B,C, ...

  3. POJ 1502 MPI Maelstrom [最短路 Dijkstra]

    传送门 MPI Maelstrom Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5711   Accepted: 3552 ...

  4. Linux 下MySQL 安装与卸载

    这个写的比较好:http://www.cnblogs.com/starof/p/4680083.html 2.卸载系统自带的Mariadb rpm -qa|grep mariadb         / ...

  5. Unity3D游戏开发之C#编程中常见数据结构的比较

    一.前言 Unity3D是如今最火爆的游戏开发引擎,它可以让我们能轻松创建诸如三维视频游戏.建筑可视化.实时三维动画等类型的互动内容.它支持2D/3D游戏开发,据不完全统计,目前国内80%的手机游戏都 ...

  6. codevs——1036 商务旅行

    1036 商务旅行  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond 题解  查看运行结果     题目描述 Description 某首都城市的商人要经常 ...

  7. hzwer与逆序对

    codevs——4163 hzwer与逆序对 貌似这个题和上个题是一样的((⊙o⊙)…)  时间限制: 1 s  空间限制: 256000 KB  题目等级 : 黄金 Gold 题解       题目 ...

  8. Access restriction: The method 'CharacterEncoder.encode(byte[])' is not API...

    问题描述:Access restriction: The method 'CharacterEncoder.encode(byte[])' is not API... 解决方法:这种错误是eclips ...

  9. Centos7 下的防火墙端口配置

    如果外部不能访问,需要查看防火墙以及服务器的端口安全设置. 防火墙的操作 查看所有打开的端口: firewall-cmd --zone=public --list-ports 添加 firewall- ...

  10. Android Studio如何Format代码

    Android Studio如何Format代码 Reformat code Shift + CTRL + ALT + L (Win) OPTION + CMD + L (Mac)