题目链接

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

可用二分法与BFS法解决,但有更好的算法。先求出最小生成树,起点和终点在树上的唯一路径就是我们所要找的路径。需要注意的是这道题只用求最短的那条边,所以如果用kruskal算法不用将最小生成树求出来,只要起点和终点连通即可。

#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath> using namespace std; struct aa{
int x;
int y;
aa(int x1,int y1):x(x1),y(y1){}
}; struct bb{
int a;
int b;
int c;
bb(int a1,int b1,int c1):a(a1),b(b1),c(c1){}
bool operator < (const bb &rhs)const{
return c > rhs.c;
}
}; vector<aa>s;
priority_queue<bb>z;
int p[]; int find_z(int x){
return p[x]==x?x:p[x]=find_z(p[x]);
} int main(){
int n;
int yy=;
while(~scanf("%d",&n)){
if(n==)break;
yy++;
s.clear();
while(!z.empty())z.pop(); for(int i=,q,w;i<n;i++){
scanf("%d%d",&q,&w);
s.push_back(aa(q,w));
} for(int i=,o;i<n;i++){
for(int j=;j<n;j++){
o=(s[i].x-s[j].x)*(s[i].x-s[j].x)+(s[i].y-s[j].y)*(s[i].y-s[j].y);
z.push(bb(i,j,o));
}
} for(int i=;i<n;i++)p[i]=i;
while(!z.empty()){
bb zz=z.top(); z.pop();
if( find_z(zz.a) != find_z(zz.b) ){
p[find_z(zz.a)]=find_z(zz.b);
}
if(find_z()==find_z()){
printf("Scenario #%d\n",yy);
double sss=(double)zz.c;
printf("Frog Distance = %.3lf\n\n",sqrt(sss));
break;
}
}
}
return ;
}

poj-2253(最小瓶颈路问题)的更多相关文章

  1. 最小瓶颈路 Uva 534 Frogger

    说明:关于Uva的题目,可以在vjudge上做的,不用到Uva(那个极其慢的)网站去做. 最小瓶颈路:找u到v的一条路径满足最大边权值尽量小 先求最小生成树,然后u到v的路径在树上是唯一的,答案就是这 ...

  2. UVALive 5713 Qin Shi Huang's National Road System秦始皇修路(MST,最小瓶颈路)

    题意: 秦始皇要在n个城市之间修路,而徐福声可以用法术位秦始皇免费修1条路,每个城市还有人口数,现要求徐福声所修之路的两城市的人口数之和A尽量大,而使n个城市互通需要修的路长B尽量短,从而使得A/B最 ...

  3. UVA 11354 Bond(最小瓶颈路+倍增)

    题意:问图上任意两点(u,v)之间的路径上,所经过的最大边权最小为多少? 求最小瓶颈路,既是求最小生成树.因为要处理多组询问,所以需要用倍增加速. 先处理出最小生成树,prim的时间复杂度为O(n*n ...

  4. 【UVA534】Frogger 最小瓶颈路

    题目大意:给定一张 N 个点的完全图,求 1,2 号节点之间的一条最小瓶颈路. 题解:可知,最小瓶颈路一定存在于最小生成树(最小瓶颈树)中.因此,直接跑克鲁斯卡尔算法,当 1,2 号节点在同一个联通块 ...

  5. 【20181102T2】飞越行星带【智商题+最小瓶颈路】

    题面 [正解] 一眼不可做啊 --相当于求路线上穿过的点最小距离最大 最小最大--二分啊 现在相当于给一个直径,要判断这个直径是否能从左边穿到右边 我们可以在距离不超过直径的点连一条边,\(y=0\) ...

  6. UVa 11354 邦德(最小瓶颈路+LCA)

    https://vjudge.net/problem/UVA-11354 题意: 有n个城市m条道路,每条道路有一个危险系数.先在有若干个询问,要求找到一条从s到t的路,使得途径所有边的最大危险系数最 ...

  7. 【UVA10816】Travel in Desert (最小瓶颈路+最短路)

    UVA10816 Travel in Desert 题目大意 沙漠中有一些道路,每个道路有一个温度和距离,要求s,t两点间的一条路径,满足温度最大值最小,并且长度最短 输入格式 输入包含多组数据. 每 ...

  8. HDU4081:Qin Shi Huang's National Road System (任意两点间的最小瓶颈路)

    Qin Shi Huang's National Road System Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/3 ...

  9. P1396 营救(最小瓶颈路)

    题目描述 “咚咚咚……”“查水表!”原来是查水表来了,现在哪里找这么热心上门的查表员啊!小明感动的热泪盈眶,开起了门…… 妈妈下班回家,街坊邻居说小明被一群陌生人强行押上了警车!妈妈丰富的经验告诉她小 ...

  10. LOJ#137. 最小瓶颈路 加强版(Kruskal重构树 rmq求LCA)

    题意 三倍经验哇咔咔 #137. 最小瓶颈路 加强版 #6021. 「from CommonAnts」寻找 LCR #136. 最小瓶颈路 Sol 首先可以证明,两点之间边权最大值最小的路径一定是在最 ...

随机推荐

  1. ES6和node的模块化

    ES6 模块的设计思想是尽量的静态化,使得编译时就能确定模块的依赖关系,以及输入和输出的变量.CommonJS 和 AMD 模块,都只能在运行时确定这些东西.比如,CommonJS 模块就是对象,输入 ...

  2. C++关于锁的总结(一)

    C++关于锁的总结(一) 线程中的锁分为两种,互斥锁和共享锁. 相关的头文件有<mutex>,<shared_mutex>,前者具有std::unique_lock操作,用于实 ...

  3. VS GIT 使用入门---我只是搬运工

    网上资料推荐 GitHub 新手详细教程 - Hanani_Jia的博客 - CSDN博客 https://blog.csdn.net/Hanani_Jia/article/details/77950 ...

  4. linux系统挂载u盘拷贝文件

    linux系统在不能远程的情况下用u盘传文件(比如服务器装上系统还没配IP),需要先将u盘挂载到系统中的某个位置,再使用cp命令拷贝文件,简要步骤如下: 1.把U盘插入Linux电脑,确保U盘指示灯是 ...

  5. 组件使用v-model、$listeners、.sync(区别于v-model的双向数据绑定)

    自定义组件 自定义组件的v-model 首先我们先说一下在自定义组件中使用v-model的必要条件 在自定义的组件中要有input(这里我们先不讨论单选复选框) 在自定义组件的模板对象中要有props ...

  6. 2020.02.01【NOIP提高组】模拟B 组总结反思——数列(sequence) 树 【2012东莞市选】时间流逝 挖掘机技术哪家强

    T1 数列(sequence) 比赛时 我自以为是地打了简简单单一个判断--- 之后 Waiting-- T2 2753. 树(tree) 比赛时 这题我居然比赛时也想了很久,可能是因为我太懒,我很早 ...

  7. script标签的async和defer

    兼容性 IE对于defer一直都支持,async属性IE6-9都没有支持,IE10及以上支持 相同点与不同点 带有async或defer的script都会立刻下载并不阻塞页面解析,而且都提供一个可选的 ...

  8. xctf-i-got-id-200(perl网页文件+ARGV上传造成任意文件读取)

    打开url发现有三个链接,点进去都是.pl文件,且只有files可以上传文件. .pl文件都是用perl编写的网页文件 这里上传了又将文件的内容全部打印出来,那么猜想后台应该用了param()函数. ...

  9. Linux X_window与文本模式的切换

    用x_window启动的情况下的切换方法: [Ctrl] + [Alt] + [F1] ~ [F6]  :文字接口登陆 tty1 ~ tty6 终端机: [Ctrl] + [Alt] + [F7]   ...

  10. Bad Hair Day【单调栈】

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAzMAAANgCAIAAACX06G4AAAgAElEQVR4Aey9e5RlW13fuw40HORxfI ...