题目链接

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. kaks calculator批量计算多个基因的选择压力kaks值

    欢迎来到"bio生物信息"的世界 今天给大家带来"批量计算kaks值"的技能. 关于kaks的背景知识我就不介绍了,感兴趣的自行搜索,这里直接开始讲怎么批量计算 ...

  2. Centos7下安装包方式安装MySQL

    安装包下载地址:https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.27-1.el7.x86_64.rpm-bundle.tar 第一步:在 /h ...

  3. c#---out参数

    一个方法有多个返回值时,返回值类型相同可以返回一个数组 static void Main(string[] args) { , , , , , , , , , }; int[] result = Ge ...

  4. 如何修复MacBook Pro过热:保持MacBook散热的13个技巧

    尽管MacBook Pro是一台能处理繁重工作量的高能效机器,但它却无法像市场上其他笔记本电脑一样避免过热.至于什么可以防止发热,那不是一两个技巧就能解决的问题.相反,这是一组技巧可以解决的挑战. 因 ...

  5. STM32 & RT-Thread的逆向入门

    STM32 & RT-Thread的逆向入门 backahasten@0xFA ​                现在,各种MCU的价格越来越低,同等条件下能买到的ROM和RAM资源也多了.对 ...

  6. Excel创建下拉列表限制数据有效性

    方法 选中目标区域,点击菜单栏[数据]-[数据验证]-验证条件选择[序列]-输入所需文本即可

  7. Windows添加管理员用户

    使用命令提示符添加用户并提升管理员权限 net user 查看当前所有系统用户 net user dan 123456 /add 添加用户名为dan 密码为123456的用户 net localgro ...

  8. LAMP环境搭建与配置(3)

    PHP配置 查看PHP配置文件的位置 #  /usr/local/php/bin/php   -i  |grep  -i  "loaded configuration file" ...

  9. 跳跃【BFS】

    From 牛客网:https://ac.nowcoder.com/acm/problem/25160

  10. PAT (Advanced Level) Practice 1011 World Cup Betting (20 分) (找最值)

    With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excite ...