传送门:

http://poj.org/problem?id=2253

Frogger
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 58328   Accepted: 18293

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

分析:
题目意思:青蛙a在石头1上,青蛙b在石头2上,青蛙a要去找青蛙b玩,问你从从石头1到石头2的最短路里最大的距离是多少 做法:
可以用prim写,但是prim是求MST的,这样只要求1到2的最短路上的最大边就可以了
找j的时候,找到了2就跳出去
注意:
代码里面是0号石头 ,1号石头,而不是分析中的1号,2号石头 code:
#include <iostream>
#include <cstdio>
#include<stdio.h>
#include<algorithm>
#include<cstring>
#include<math.h>
#include<memory>
using namespace std;
typedef long long LL;
#define INF 0x3f3f3f3f
#define max_v 205
struct node
{
double x,y;
}p[max_v];
double g[max_v][max_v];
int n,c=;
void init()
{
for(int i=;i<n;i++)
for(int j=;j<n;j++)
g[i][j]=INF;
}
void prim(int s)
{
double lowcost[n];
int used[n];
for(int i=;i<n;i++)
{
lowcost[i]=g[s][i];
used[i]=;
}
double ans=;
used[s]=;
for(int i=;i<n;i++)
{
int j=;
for(int k=;k<n;k++)
{
if(!used[k]&&lowcost[k]<lowcost[j])
j=k;
}
if(j==)
break;
ans=max(ans,lowcost[j]);
used[j]=;
if(j==)
break;
for(int k=;k<n;k++)
{
if(!used[k]&&g[j][k]<lowcost[k])
{
lowcost[k]=g[j][k];
}
}
}
printf("Scenario #%d\n",c++);
printf("Frog Distance = %0.3f\n\n",ans);
}
double f(int i,int j)
{
double x=p[i].x-p[j].x;
double y=p[i].y-p[j].y;
return sqrt(x*x+y*y);
}
int main()
{
while(~ scanf("%d",&n))
{
if(n==)
break;
for(int i=;i<n;i++)
{
scanf("%lf %lf",&p[i].x,&p[i].y);
}
init();
for(int i=;i<n;i++)
{
for(int j=i+;j<n;j++)
{
g[i][j]=g[j][i]=f(i,j);
}
}
prim();
}
return ;
}

poj 2253 Frogger 最小瓶颈路(变形的最小生成树 prim算法解决(需要很好的理解prim))的更多相关文章

  1. 【UVA534】Frogger 最小瓶颈路

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

  2. POJ 2253 Frogger【最短路变形/最小生成树的最大权/最小瓶颈树/A到B多条路径中的最小的最长边】

    Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fiona Frog who is sit ...

  3. POJ 2253 Frogger【最短路变形——路径上最小的最大权】

    链接: http://poj.org/problem?id=2253 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...

  4. poj 2253 Frogger (最长路中的最短路)

    链接:poj 2253 题意:给出青蛙A,B和若干石头的坐标,现青蛙A想到青蛙B那,A可通过随意石头到达B, 问从A到B多条路径中的最长边中的最短距离 分析:这题是最短路的变形,曾经求的是路径总长的最 ...

  5. poj 2253 Frogger (最小最大路段)【dijkstra】

    <题目链接> 题目大意: 给出青蛙A,B和若干石头的坐标,现青蛙A想到青蛙B那,A可通过任意石头到达B,问从A到B多条路径中最小的最长边. 解题分析: 这是最短路的一类典型题目,与普通的最 ...

  6. POJ 2253 Frogger(最小最大距离)

    题意  给你n个点的坐标  求第1个点到第2个点的全部路径中两点间最大距离的最小值 非常水的floyd咯 #include<cstdio> #include<cmath> #i ...

  7. Codeforces 632F - Magic Matrix(暴力 bitset or Prim 求最小生成树+最小瓶颈路)

    题面传送门 开始挖老祖宗(ycx)留下来的东西.jpg 本来想水一道紫题作为 AC 的第 500 道紫题的,结果发现点开了道神题. 首先先讲一个我想出来的暴力做法.条件一和条件二直接扫一遍判断掉.先将 ...

  8. 最小瓶颈路 Uva 534 Frogger

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

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

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

随机推荐

  1. linux环境下mysql 5.7.1X 如何重置root密码

    1,vi  /etc/my.cnf [mysqld]下加入参数skip-grant-tables   保存退出. 2,重启mysql [root@21yunwei src]# /etc/init.d/ ...

  2. FATAL bad indentation of a mapping entry at line 83, column 3: branch: master 已解决;

    部署hexo 时候,修改完_config.yml  文件后更新报错如下,问题解决: FATAL bad indentation of a mapping entry at line 83, colum ...

  3. 爬虫必备—BeautifulSoup

    BeautifulSoup是一个模块,该模块用于接收一个HTML或XML字符串,然后将其进行格式化,之后便可以使用他提供的方法进行快速查找指定元素,从而使得在HTML或XML中查找指定元素变得简单. ...

  4. 解决servlet在web.xml中的路径跳转问题

    <?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" ...

  5. 4类Storage方案(AS开发实战第四章学习笔记)

    4.1 共享参数SharedPreferences SharedPreferences按照key-value对的方式把数据保存在配置文件中,该配置文件符合XML规范,文件路径是/data/data/应 ...

  6. String类型的学习

    一 :关于两个string类型变量是否相等: 请运行以下示例代码StringPool.java,查看其输出结果.如何解释这样的输出结果?从中你能总结出什么? 分析: 首先为s0开辟空间,然后给s1开辟 ...

  7. DockerFile简介以及使用

    DockerFile是用来构建docker镜像的构建文件,是有一系列命令和参数构成的脚本 构建的三步骤:编写dockerfile文件→build构建→docker run dockerfile保留字指 ...

  8. python 3 输入和输出

    一.普遍的输入和输出 1.输入 在python3中,函数的输入格式为:input(),能够接受一个标准输入数据,返回string类型. input() 函数是从键盘作为字符串读取数据,不论是否使用引号 ...

  9. winfrom 实现窗体圆角

    在窗体中加入一下代码 #region 窗体圆角的实现 private void ComFrmBase_Resize(object sender, EventArgs e) { if (this.Win ...

  10. python之路——网络基础

    你现在已经学会了写python代码,假如你写了两个python文件a.py和b.py,分别去运行,你就会发现,这两个python的文件分别运行的很好.但是如果这两个程序之间想要传递一个数据,你要怎么做 ...