题目链接: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[]);
}
}

最新文章

  1. freebsd 系统时间
  2. Jquery ajax提交表单几种方法
  3. Linux 文件的基本操作
  4. oracle 中start with 的用法
  5. MySQL关闭过程详解和安全关闭MySQL的方法
  6. Gunicorn + Django 部署
  7. 多线程的单元测试工具 - GroboUtils
  8. [转] Webpack 入门指迷
  9. Android-设置PullToRefresh下拉刷新样式
  10. How to remotely shut down any PC on same network
  11. 201521123060 《Java程序设计》第3周学习总结
  12. codeforces 862B B. Mahmoud and Ehab and the bipartiteness
  13. Python调用外部程序——os.system()和subprocess.call
  14. SQLServer之删除约束
  15. shell实现带颜色输出的进度条
  16. Boost property_tree解析json
  17. 自定义ScrollView 实现上拉下拉的回弹效果--并且子控件中有Viewpager的情况
  18. Java 迭代器综述
  19. 为什么我们做分布式使用Redis?
  20. 使ipconfig命令结果更整洁

热门文章

  1. 巧克力王国 BZOJ 2850
  2. Bayan 2015 Contest Warm Up D. CGCDSSQ (math,pair,map,暴力)
  3. Android UI自定义Spinner下拉框(用popuwindow实现)-转
  4. Controller配置汇总
  5. ORACLE RMAN增量备份经典理解
  6. (12)centos之stmp服务器
  7. Codeforces 655E Beautiful Subarrays【01trie树】
  8. P1540 机器翻译(STL 链表)
  9. mybatis注解@selectKey对于db2数据库的使用
  10. java设计模式图