说明:关于Uva的题目,可以在vjudge上做的,不用到Uva(那个极其慢的)网站去做。

最小瓶颈路:找u到v的一条路径满足最大边权值尽量小

先求最小生成树,然后u到v的路径在树上是唯一的,答案就是这条路径。

Uva 534 Frogger

Time Limit: 3000MS 64bit IO Format: %lld & %llu

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 file 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

/*-------------------------------------------------*/
解析:

原来的想法是先求最小生成树,然后倍增求出答案。这样虽然可以但是比较麻烦。对于要求U--V最小瓶颈路的总长度,这是最快的方法。 介于这道题是单对询问路上最大边的最小值,我们可以找到更简单的做法:郭华阳在国家集训队论文里介绍了最小生成树的性质。就是在kruskal算法执行的时候第一次将两个点(或者说两个点的集合)连起来的那条边就是这两点的最小瓶颈路上最大边。(因为kruskal是从小到大依次连边的。)一旦明白了让这条性质这题就变得简单多了。

 #include<iostream>
using namespace std;
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#define N 205
struct Edge{
int u,v;
double w;
}edge[N*N];
int n,t;
struct D{
double x,y;
}dian[N];
int father[N];
void add_edge(int a,int b)
{
++t;
edge[t].u=a;
edge[t].v=b;
edge[t].w=sqrt((dian[a].x-dian[b].x)*(dian[a].x-dian[b].x)+(dian[a].y-dian[b].y)*(dian[a].y-dian[b].y));
}
bool cmp(Edge P,Edge Q)
{
return P.w<Q.w;
}
int find(int x)
{
return (father[x]==x?x:father[x]=find(father[x]));
}
void kruskal(double &ans)
{
for(int i=;i<=n;++i)
father[i]=i;
sort(edge+,edge+t+,cmp);
for(int l=;l<=t;++l)
{
int f1=find(edge[l].u);
int f2=find(edge[l].v);
if(f1==f2) continue;
father[f2]=f1;
if(find()==find()) /*1是起点,2是终点,在kruskal算法执行的时候第一次将两个点(或者说两个点的集合)连起来的那条边就是这两点的最小瓶颈路上最大边。*/
{
ans=edge[l].w;/*这个性质由kruskal算法的过程即可知道*/
return;
}
}
}
int main()
{
int topt=;
while(scanf("%d",&n)==)
{
topt++;
if(n==) break;
t=;
for(int i=;i<=n;++i)
{
scanf("%lf%lf",&dian[i].x,&dian[i].y);
if(i==)continue;
for(int j=;j<i;++j)
add_edge(j,i);
}
double ans;
kruskal(ans);
printf("Scenario #%d\n",topt);
printf("Frog Distance = %0.3lf\n\n",ans);
}
return ;
}

最小瓶颈路 Uva 534 Frogger的更多相关文章

  1. 【uva 534】Frogger(图论--最小瓶颈路 模版题)

    题意:平面上有N个石头,给出坐标.一只青蛙从1号石头跳到2号石头,使路径上的最长便最短.输出这个值.(2≤N≤200) 解法:最小瓶颈树.而由于这题N比较小便可以用2种方法:1.最短路径中提到过的Fl ...

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

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

  3. 【UVA534】Frogger 最小瓶颈路

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

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

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

  5. UVA 534 - Frogger(kruskal扩展)

    UVA 534 - Frogger 题目链接 题意:给定一些点.如今要求一条路径从第一个点能跳到第二个点,而且这个路径上的最大距离是最小的 思路:利用kruskal算法,每次加最小权值的边进去,推断一 ...

  6. POJ 2235 Frogger / UVA 534 Frogger /ZOJ 1942 Frogger(图论,最短路径)

    POJ 2235 Frogger / UVA 534 Frogger /ZOJ 1942 Frogger(图论,最短路径) Description Freddy Frog is sitting on ...

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

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

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

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

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

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

随机推荐

  1. jquery fadeOut 异步

    1. 概述 jquery实现动画效果的函数使用起来很方便,不过动画执行是异步的, 所以要把自定义的操作放在回调函数里. 2. example <html> <body> < ...

  2. ServiceLocator是反模式

    关于ServiceLocator模式 http://www.cnblogs.com/hwade/archive/2011/01/30/CommonServiceLocator.html 为什么是Ant ...

  3. [js开源组件开发]图片放大镜

    图片放大镜 一般情况下,手机由于屏幕太小,会有图片上看不清的问题,所以我就做了一个放大镜的js效果,支持pc和移动端.它的原理是利用的backgroundsize来实现的,所以你的浏览器首先要支持这个 ...

  4. 选择Web API还是WCF

    ASP.NET WCF是.NET平台服务开发的一站式框架,那么为什么还要有ASP.NET Web API呢?简单来说,ASP.NET Web API的设计和构建只考虑了一件事情,那就是HTTP,而WC ...

  5. 使用WCF对外提供接口

    本篇将通过WCF以webservices的方式对外提供接口.同时使用NUnit对webservices中的方法进行单元测试. 开发契约 contract Contract项目为类库项目,该项目下会包含 ...

  6. CSS中的三种基本的定位机制

    CSS 定位机制 CSS 有三种基本的定位机制:普通流.浮动和绝对定位. 一.普通流 除非专门指定,否则所有框都在普通流中定位.普通流中元素框的位置由元素在(X)HTML中的位置决定.块级元素从上到下 ...

  7. 访问SAP的Domain的Value Range

    访问Domain的Value Range有两种方法: 1.直接访问表 dd07l和dd07T     select * from dd07l            where domname   = ...

  8. Oracle之自动收集统计信息

    一.Oracle 11g 在Oracle的11g版本中提供了统计数据自动收集的功能.在部署安装11g Oracle软件过程中,其中有一个步骤便是提示是否启动这个功能(默认是启用这个功能). 在这里介绍 ...

  9. SQL Server 分组 去除从复列

    下面先来看看例子: table表 字段1 字段2 id        name 1           a 2           b 3           c 4           c 5    ...

  10. android 永不关闭toast

    Toast信息提示框之所以在显示一定时间后会自动关闭,是因为在系统中有一个Toast队列;那么有些时候需要这个Toast信息提示框长时间显示,直到需要关闭它时通过代码来控制,而不是让系统自动来关闭To ...