Frogger

Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

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 题目大意:给出n个点的坐标,源点是1,终点是2。问你一条从源点能到达终点的路径中的最长边且满足不大于其他可到达终点路径中的最小边长度。(即求最长边的最小值)。 解题思路:改变Dijkstra中的d数组的含义,在更新d数组的时候条件也变一下。d[i]表示从源点到i点的最长边最小值。那么更新条件就变为if( d[i] > max( d[u] ,distance(u,i) ) ) d[i] = max(d[u] , distance (u,i) )。表示当前在u点时,如果路径中的最长边长度,跟 distance( u ,i )的最大值还小于d[i](i点的最大边长度),那么说明原来到达i点时的最长边还不够小,那么更新即可。
结果必须输出%.3f,而不是%.3lf。这里一直错。
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<vector>
#include<math.h>
#include<string.h>
using namespace std;
const int maxn = 1e4;
const int INF = 0x3f3f3f3f;
struct HeapNode{
double d;
int u;
bool operator < (const HeapNode &rhs)const {
return d > rhs.d;
}
};
struct Edge{
int from,to;
double dist;
};
struct node{
double x,y;
}cor[maxn];
priority_queue<HeapNode>PQ;
vector<Edge>edge;
vector<int>G[maxn];
double d[maxn];
int vis[maxn];
int n,m;
double distan(node a, node b){
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
void AddEdge(int u,int v,double dis){
edge.push_back((Edge){u,v,dis});
m = edge.size();
G[u].push_back(m-1);
}
void Dijstra(int s){
for(int i = 0; i<= n;i++){
d[i] = INF;
}
memset(vis,0,sizeof(vis));
d[s] = 0.00;
PQ.push( (HeapNode){d[s],s} );
while(!PQ.empty()){
HeapNode x = PQ.top();
PQ.pop();
int u = x.u;
if(u == 1){
break;
}
if(vis[u]) continue;
vis[u] = 1;
for(int i = 0; i < G[u].size(); i++){
Edge & e = edge[G[u][i]];
if( (!vis[e.to]) && d[e.to] > max( d[e.from], e.dist) ){
d[e.to] = max(d[e.from] , e.dist);
PQ.push( (HeapNode){ d[e.to] , e.to } );
}
}
}
}
void init(int n){
for(int i = 0; i <= n;i++){
G[i].clear();
}
edge.clear();
while(!PQ.empty())
PQ.pop();
}
int main(){
int cnt = 0;
while(scanf("%d",&n)!=EOF && n){
init(n);
for(int i = 0; i < n; i++){
scanf("%lf%lf",&cor[i].x,&cor[i].y);
for(int j = 0; j < i; j++){
AddEdge( i, j, distan(cor[i],cor[j]));
AddEdge( j, i, distan(cor[j],cor[i]));
}
}
Dijstra(0);
printf("Scenario #%d\n",++cnt);
printf("Frog Distance = %.3f\n",d[1]);
puts("");
}
return 0;
} /*
这里给出4个点6条边,不是坐标表示
4 6
1 4 3
1 2 4
1 3 5
2 4 2
3 4 6
2 3 8
可以看出为什么需要改成那样的更新条件 */

  

  


POJ 2253 ——Frogger——————【最短路、Dijkstra、最长边最小化】的更多相关文章

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

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

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

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

  3. POJ 2253 Frogger (最短路)

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

  4. poj 2253 Frogger(最短路 floyd)

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

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

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

  6. POJ 2253 Frogger(dijkstra 最短路

    POJ 2253 Frogger Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fion ...

  7. POJ. 2253 Frogger (Dijkstra )

    POJ. 2253 Frogger (Dijkstra ) 题意分析 首先给出n个点的坐标,其中第一个点的坐标为青蛙1的坐标,第二个点的坐标为青蛙2的坐标.给出的n个点,两两双向互通,求出由1到2可行 ...

  8. 最短路(Floyd_Warshall) POJ 2253 Frogger

    题目传送门 /* 最短路:Floyd算法模板题 */ #include <cstdio> #include <iostream> #include <algorithm& ...

  9. POJ 2253 Frogger ,poj3660Cow Contest(判断绝对顺序)(最短路,floyed)

    POJ 2253 Frogger题目意思就是求所有路径中最大路径中的最小值. #include<iostream> #include<cstdio> #include<s ...

随机推荐

  1. C#中打开文件、目录、保存窗口

    打开文件代码: try { OpenFileDialog of = new OpenFileDialog(); of.ShowDialog(); txt_destFilePath.Text = of. ...

  2. Asp.net 实现只能允许一个账号同时只能在一个地方登录

    先上帮助类: /// <summary> /// 单点登录帮助类 /// </summary> public class SSOHelper { /// <summary ...

  3. maven spring3.2.5

    出现的情形: 开发环境: spring3.2.5 + springmvc +spirngDATA +maven 一. 偶然的spring Junit4测试 加载applicationContext.x ...

  4. svn merge和branch 详解

    1.本地Repository的创建 repository的创建很简单,假设我要在D:\TortoiseSVN\TestRepository目录中创建repository,只需右键TestReposit ...

  5. SpringBoot04 SpringBoot 和 MyBatis 整合

    1 所需的jar包 mysql驱动包:mysql-connector-java 数据库链接池:druid mybatis对应jar包:mybatis-spring-boot-starter 分页查询对 ...

  6. Angular14 利用Angular2实现文件上传的前端、利用springBoot实现文件上传的后台、跨域问题

    一.angular2实现文件上传前端 Angular2使用ng2-file-upload上传文件,Angular2中有两个比较好用的上传文件的第三方库,一个是ng2-file-upload,一个是ng ...

  7. 杭电acm 1049题

    一道水题..... 大意是一条1inch的虫子在一个n inch的盒子的底部,有足够的能够每一分钟往上爬u inch,但是需要休息一分钟,这期间会往下掉d inch,虫子爬到盒子口即认为结束.要求计算 ...

  8. ARC097C K-th Substring

    传送门 题目 You are given a string s. Among the different substrings of s, print the K-th lexicographical ...

  9. 9、scala函数式编程-集合操作

    一.集合操作1 1.Scala的集合体系结构 // Scala中的集合体系主要包括:Iterable.Seq.Set.Map.其中Iterable是所有集合trait的根trai.这个结构与Java的 ...

  10. 5.6 安装Virtual box

    本以为安装虚拟机很复杂的样子,经过kevin一指点,发现soeasy.废话少说,直接上图片: 将安装包放到自己的目录下: 安装完后,可以在搜索框中搜索:virtual 会出现安装好的虚拟机盒子.