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

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

Http

POJ:https://vjudge.net/problem/POJ-2253

UVA:https://vjudge.net/problem/UVA-534

ZOJ:https://vjudge.net/problem/ZOJ-1942

Source

图论,最短路径

题目大意

求两点之间的一条路径满足这条路径上最大的边权最小

解决思路

运用改进的spfa算法就可以了

代码

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
#include<queue>
using namespace std; #define ll long long const int maxN=3000;
const int inf=147483647; class Edge
{
public:
int v;
ll w;
}; int n,m;
vector<Edge> E[maxN];
ll Dist[maxN];
int Px[maxN];
int Py[maxN];
bool inqueue[maxN];
queue<int> Q; int main()
{
int ti=0;
while (cin>>n)
{
if (n==0)
break;
for (int i=1;i<=n;i++)
{
E[i].clear();
}
memset(Dist,-1,sizeof(Dist));
for (int i=1;i<=n;i++)
cin>>Px[i]>>Py[i];
for (int i=1;i<=n;i++)
for (int j=i+1;j<=n;j++)
{
ll dist=(Px[i]-Px[j])*(Px[i]-Px[j])+(Py[i]-Py[j])*(Py[i]-Py[j]);
E[i].push_back((Edge){j,dist});
E[j].push_back((Edge){i,dist});
}
memset(inqueue,0,sizeof(inqueue));
while (!Q.empty())
Q.pop();
Dist[1]=0;
inqueue[1]=1;
Q.push(1);
do
{
int u=Q.front();
Q.pop();
inqueue[u]=0;
for (int i=0;i<E[u].size();i++)
{
int v=E[u][i].v;
if ((max(Dist[u],E[u][i].w)<Dist[v])||(Dist[v]==-1))
{
Dist[v]=max(Dist[u],E[u][i].w);
if (inqueue[v]==0)
{
Q.push(v);
inqueue[v]=1;
}
}
}
}
while (!Q.empty());
ti++;
printf("Scenario #%d\nFrog Distance = %.3f\n\n",ti,sqrt(Dist[2]*1.0));
//cout<<Dist[2]<<endl;
}
return 0;
}

POJ 2235 Frogger / UVA 534 Frogger /ZOJ 1942 Frogger(图论,最短路径)的更多相关文章

  1. 最小瓶颈路 Uva 534 Frogger

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

  2. UVA 534 - Frogger(kruskal扩展)

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

  3. POJ 1797 Heavy Transportation / SCU 1819 Heavy Transportation (图论,最短路径)

    POJ 1797 Heavy Transportation / SCU 1819 Heavy Transportation (图论,最短路径) Description Background Hugo ...

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

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

  5. POJ 1852 Ants || UVA 10881 - Piotr's Ants 经典的蚂蚁问题

    两题很有趣挺经典的蚂蚁问题. 1.n只蚂蚁以1cm/s的速度在长为L的竿上爬行,当蚂蚁爬到竿子的端点就会掉落.当两只蚂蚁相撞时,只能各自反向爬回去.对于每只蚂蚁,给出距离左端的距离xi,但不知道它的朝 ...

  6. POJ 1364 King (UVA 515) 差分约束

    http://poj.org/problem?id=1364 http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemi ...

  7. 专题复习--背包问题+例题(HDU 2602 、POJ 2063、 POJ 1787、 UVA 674 、UVA 147)

    *注 虽然没什么人看我的博客但我还是要认认真真写给自己看 背包问题应用场景给定 n 种物品和一个背包.物品 i 的重量是 w i ,其价值为 v i ,背包的容量为C.应该如何选择装入背包中的物品,使 ...

  8. Poj(3522),UVa(1395),枚举生成树

    题目链接:http://poj.org/problem?id=3522 Slim Span Time Limit: 5000MS   Memory Limit: 65536K Total Submis ...

  9. 2018 Spring Single Training B (uva 572,HihoCoder 1632,POJ 2387,POJ 2236,UVA 10054,HDU 2141)

    这场比赛可以说是灰常的水了,涨信心场?? 今下午义务劳动,去拿着锄头发了将近一小时呆,发现自己实在是干不了什么,就跑到实验室打比赛了~ 之前的比赛补题补了这么久连一场完整的都没补完,结果这场比完后一小 ...

随机推荐

  1. 20155222卢梓杰 实验五 MSF基础应用

    实验五 MSF基础应用 1.一个主动攻击实践,如ms17_010_eternalblue漏洞; 本次攻击目标是win7虚拟机 首先进行相应配置 然后点launch 就成功了 针对win7的漏洞还是相对 ...

  2. 20155232《网络对抗》Exp3 免杀原理与实践

    20155232<网络对抗>Exp3 免杀原理与实践 问题回答 1.基础问题回答 (1)杀软是如何检测出恶意代码的? 基于特征码的检测 特征码:一段特征码就是一段或多段数据. 如果一个可执 ...

  3. oracle移动数据/修改数据文件路径

    参考:http://wwyz998.blog.163.com/blog/static/321867852011117111832334/ oracle移动数据文件 1.连接到数据库 [oracle@l ...

  4. SQL Server 常用内置函数

    本文用于收集在运维中经常使用的系统内置(built-in)函数,持续整理中 一,常用Metadata函数 1,查看数据库的ID和Name db_id(‘DB Name’),db_name('DB ID ...

  5. 谷歌商店高级搜索 Google play advanced search

    这个问题一直搜索了很久都没有答案,后来在StackOverflow上提问,很久也没人回答. 详见我的SO:https://stackoverflow.com/questions/52939493/ho ...

  6. Scrapy的日志等级和请求传参

    日志等级 日志信息:   使用命令:scrapy crawl 爬虫文件 运行程序时,在终端输出的就是日志信息: 日志信息的种类: ERROR:一般错误: WARNING:警告: INFO:一般的信息: ...

  7. Linux下安装maven(mvn命令)

    Maven(mvn)是基于项目对象模型(POM project object model),可以通过一小段描述信息(配置)来管理项目的构建,报告和文档的软件项目管理工具(百度百科) 简单理解为一个打包 ...

  8. [环境配置]Ubuntu 16.04 源码编译安装OpenCV-3.2.0+OpenCV_contrib-3.2.0及产生的问题

    1.OpenCV-3.2.0+OpenCV_contrib-3.2.0编译安装过程 1)下载官方要求的依赖包 GCC 4.4.x or later CMake 2.6 or higher Git GT ...

  9. Mistakes I Made(as a developer)...大龄程序员的忠告...(部分转...)

    在2006年,我开始了编程工作.当意识到来到了十年这个重要的时间关口时,我觉得有必要回顾一下这十年间所犯下的错误,做一做经验总结,并且给正在这个职业上奋斗的人们提出我的一些忠告.开发行业变化得很快,我 ...

  10. 统计学习方法c++实现之六 支持向量机(SVM)及SMO算法

    前言 支持向量机(SVM)是一种很重要的机器学习分类算法,本身是一种线性分类算法,但是由于加入了核技巧,使得SVM也可以进行非线性数据的分类:SVM本来是一种二分类分类器,但是可以扩展到多分类,本篇不 ...