POJ 2235 Frogger / UVA 534 Frogger /ZOJ 1942 Frogger(图论,最短路径)
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(图论,最短路径)的更多相关文章
- 最小瓶颈路 Uva 534 Frogger
说明:关于Uva的题目,可以在vjudge上做的,不用到Uva(那个极其慢的)网站去做. 最小瓶颈路:找u到v的一条路径满足最大边权值尽量小 先求最小生成树,然后u到v的路径在树上是唯一的,答案就是这 ...
- UVA 534 - Frogger(kruskal扩展)
UVA 534 - Frogger 题目链接 题意:给定一些点.如今要求一条路径从第一个点能跳到第二个点,而且这个路径上的最大距离是最小的 思路:利用kruskal算法,每次加最小权值的边进去,推断一 ...
- POJ 1797 Heavy Transportation / SCU 1819 Heavy Transportation (图论,最短路径)
POJ 1797 Heavy Transportation / SCU 1819 Heavy Transportation (图论,最短路径) Description Background Hugo ...
- 【uva 534】Frogger(图论--最小瓶颈路 模版题)
题意:平面上有N个石头,给出坐标.一只青蛙从1号石头跳到2号石头,使路径上的最长便最短.输出这个值.(2≤N≤200) 解法:最小瓶颈树.而由于这题N比较小便可以用2种方法:1.最短路径中提到过的Fl ...
- POJ 1852 Ants || UVA 10881 - Piotr's Ants 经典的蚂蚁问题
两题很有趣挺经典的蚂蚁问题. 1.n只蚂蚁以1cm/s的速度在长为L的竿上爬行,当蚂蚁爬到竿子的端点就会掉落.当两只蚂蚁相撞时,只能各自反向爬回去.对于每只蚂蚁,给出距离左端的距离xi,但不知道它的朝 ...
- POJ 1364 King (UVA 515) 差分约束
http://poj.org/problem?id=1364 http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemi ...
- 专题复习--背包问题+例题(HDU 2602 、POJ 2063、 POJ 1787、 UVA 674 、UVA 147)
*注 虽然没什么人看我的博客但我还是要认认真真写给自己看 背包问题应用场景给定 n 种物品和一个背包.物品 i 的重量是 w i ,其价值为 v i ,背包的容量为C.应该如何选择装入背包中的物品,使 ...
- Poj(3522),UVa(1395),枚举生成树
题目链接:http://poj.org/problem?id=3522 Slim Span Time Limit: 5000MS Memory Limit: 65536K Total Submis ...
- 2018 Spring Single Training B (uva 572,HihoCoder 1632,POJ 2387,POJ 2236,UVA 10054,HDU 2141)
这场比赛可以说是灰常的水了,涨信心场?? 今下午义务劳动,去拿着锄头发了将近一小时呆,发现自己实在是干不了什么,就跑到实验室打比赛了~ 之前的比赛补题补了这么久连一场完整的都没补完,结果这场比完后一小 ...
随机推荐
- c# 菜鸟包裹查询
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.W ...
- 一、InnoDB引擎
一.InnoDB的历史 MYSQL的5.1版本的时候还是使用旧的innoDB,当时orale公司推出的新的innoDB引擎, 但是需要以插件的形式编译,叫innoDB plugin : 知道MYSQL ...
- ReactJS实用技巧(1):JSX与HTML的那些不同
在项目中使用ReactJS也已经有大半年了,收获很多也踩过不少坑.不想把这个系列写成抄书似的罗列,旨在总结些常用的技巧及常见的坑,以帮助初心者快速入门,想系统学习的同学还是多阅读文档. JSX本质上与 ...
- 一次VB汇编中看-溢出计算
图文记录 一.观察程序特点和运行逻辑 带弹窗 是VB开发的 需要用户名和注册码 有弹框 具备了很简单的特点…… 错误弹框,如图 二.定位 弹窗内容入手,搜索关键字定位到关键跳,nop掉或者je改jne ...
- 记录:TensorFlow 中的 padding 方式
TensorFlow 中卷积操作和池化操作中都有一个参数 padding,其可选值有 ['VALID', 'SAME']. 在 TensorFlow 文档中只是给出了输出张量的维度计算方式,但是并没有 ...
- python之GIL理解
GIL(Global Interpreter Lock) 全局解释器锁 python3中是假的多线程,它不是真正的并行,是利用了cpu上下文的切换而已.同一时间只能有一个线程使用共享数据,其它线程处于 ...
- 技术进阶:Kubernetes高级架构与应用状态部署
在了解Kubernetes应用状态部署前,我们先看看Kubernetes的高级架构,方便更好的理解Kubernetes的状态. Kubernetes 的高级架构 包括应用程序部署模型,服务发现和负载均 ...
- ag使用需要注意的问题
1. set env 对比服务器标准配置,修改本地 /etc/apache2/sites-available/default (远程链接服务器的办法: ssh 12x.xxx.xxx.xxx) 2. ...
- OS X(10.10) python3.4 matplotlib的安装
最近在用python做一些数据处理相关的工作,当然少不了matplotlib这个模块.之前在windows下分分钟安装成功,结果到了mac下死活编译不过去. 最后还是在stackoverflow上找到 ...
- jquery实现点击复制到剪切板
1.必须有先引入 jquery库 <script type="text/javascript" src="js/jquery.js"></sc ...