POJ2253 Frogger(spfa变形)
Description
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
Output
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
题意:一只青蛙在X1,Y1的石头上,他要到X2,Y2的石头上续人,池塘上除了1、2两块石头外还有n-2块石头坐标分别为X3,Y3;X4,Y4……Xn,Yn
定义青蛙的跳跃范围为从石头一到石头二路径上所跳跃的最远距离,求跳跃范围的最小值
题解:spfa的判断稍微换一下就行了~
但要注意poj上.3f与.3lf的区别…….3f是不能用的
代码如下:
#include<cmath>
#include<queue>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define inf 0x3f3f3f3f
using namespace std; vector< pair<int,double> > g[];
double d[],x[],y[];
int vis[],n; void spfa(int u)
{
memset(vis,,sizeof(vis));
for(int i=; i<=n; i++)
{
d[i]=inf;
}
d[u]=;
queue<int> q;
q.push(u);
while(!q.empty())
{
int x=q.front();
q.pop();
vis[x]=;
int sz=g[x].size();
for(int i=; i<sz; i++)
{
int y=g[x][i].first;
double w=g[x][i].second;
if(max(d[x],w)<d[y])
{
d[y]=max(d[x],w);
if(!vis[y])
{
q.push(y);
vis[y]=;
}
}
}
}
} int main()
{
int ttt=;
while(scanf("%d",&n),n)
{
ttt++;
for(int i=;i<=n;i++)
{
g[i].clear();
}
for(int i=; i<=n; i++)
{
scanf("%lf%lf",&x[i],&y[i]);
}
for(int i=; i<=n; i++)
{
for(int j=i+; j<=n; j++)
{
double dx=x[i]-x[j],dy=y[i]-y[j];
double dist=sqrt(dx*dx+dy*dy);
g[i].push_back(make_pair(j,dist));
g[j].push_back(make_pair(i,dist));
}
}
spfa();
printf("Scenario #%d\n",ttt);
printf("Frog Distance = %.3f\n",d[]);
printf("\n");
} }
POJ2253 Frogger(spfa变形)的更多相关文章
- POJ2253——Frogger(Floyd变形)
Frogger DescriptionFreddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fi ...
- poj2253 Frogger Dijkstra变形
题目链接:http://poj.org/problem?id=2253 就是求所有路径的最大边权值的最小值 处理时每次找出距离当前的已选的节点的最短距离,然后更新每个未选节点的值 代码: #inclu ...
- NOIP2009最优贸易[spfa变形|tarjan 缩点 DP]
题目描述 C 国有 n 个大城市和 m 条道路,每条道路连接这 n 个城市中的某两个城市.任意两个 城市之间最多只有一条道路直接相连.这 m 条道路中有一部分为单向通行的道路,一部分 为双向通行的道路 ...
- POJ2253 Frogger —— 最短路变形
题目链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
- POJ-2253.Frogger.(求每条路径中最大值的最小值,最短路变形)
做到了这个题,感觉网上的博客是真的水,只有kuangbin大神一句话就点醒了我,所以我写这篇博客是为了让最短路的入门者尽快脱坑...... 本题思路:本题是最短路的变形,要求出最短路中的最大跳跃距离, ...
- POJ-2253 Frogger(最短路)
https://vjudge.net/problem/POJ-2253 题意 公青蛙想到母青蛙那里去,期间有许多石头,公青蛙可以通过这些石头跳过去.问至少要跳的最大距离,即所有路径上石头间的最大距离的 ...
- poj2253 Frogger(Floyd)
题目链接 http://poj.org/problem?id=2253 题意 给出青蛙A,B和若干石头的坐标,现在青蛙A要跳到青蛙B所在的石头上,求出所有路径中最远那一跳的最小值. 思路 Floyd算 ...
- UVA 11280 - Flying to Fredericton SPFA变形
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&c ...
- POJ-2253(最短路变形+dijikstra算法+求解所有路径中所有最长边中的一个最小值)
frogger POJ-2253 这题的代码特别像prim求解最小生成树的代码,其实两者本来也很像. 这里的d数组不再维护的起点到该点的最短距离了,而是路径中的最长距离. #include<io ...
随机推荐
- 在PHP中对查询出得数据库数据进行json编码
select.php <?php $con = mysql_connect("localhost","Thh","920920thh" ...
- show-overflow-tooltip 宽度设置
设置样式:不能放在scoped中 <style lang="scss"> .el-tooltip__popper{max-width:80%}</style> ...
- C++的三大特性?C也可以做到
C++的三大特性是什么?封装.继承与多态,那么今天这篇文章小编就来介绍一下,如何用C语言实现C++的这三个特性. 1.封装 何为封装? 在面向对象的思想中,将数据和对数据的操作封装在一起——即类. 类 ...
- 解决Maven提示:Could not read settings.xml, assuming default values
本文转载自:http://blog.csdn.net/hqocshheqing/article/details/47702049 最近在学习Maven 时总是出现 Could not read se ...
- 庖丁解牛-----Live555源码彻底解密(根据MediaServer讲解Rtsp的建立过程)
live555MediaServer.cpp服务端源码讲解 int main(int argc, char** argv) { // Begin by setting up our usage env ...
- contiki学习心路历程【转】xukai871105 大神
https://blog.csdn.net/xukai871105/article/details/9072993
- selenium新的定位方法,更简洁很方便
亲测是可以的 self.driver.find_element('id','kw').send_keys(u"凯宾斯基")
- IDA Pro 权威指南学习笔记(三) - IDA 桌面简介
IDA 的默认桌面如下图 工具栏区域(1)包含与 IDA 的常用操作对应的工具,可以使用 View -> Toolbar 显示或隐藏工具栏 可以使用 View -> Toolbars -& ...
- 阿里云ECS centos7 支持IPv6
1.编辑 /etc/sysctl.conf 文件,将其中三条禁用IPv6的设置更改为: net.ipv6.conf.all.disable_ipv6 = 0 net.ipv6.conf.default ...
- day4心得
装饰器: 定义:本质就是函数,(装饰其他函数)就是为其他函数添加附加功能 原则:1.不能修改被装饰的函数的源代码 2.不能修改被装饰的函数的调用方式 实现装饰器知识储备: 1.函数即"变量& ...