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 ...
随机推荐
- hbase官方文档(转)
FROM:http://www.just4e.com/hbase.html Apache HBase™ 参考指南 HBase 官方文档中文版 Copyright © 2012 Apache Soft ...
- EasyUI TreeJson
1. TreeJson str = GetTreeJsonByTable(dt, "); StringBuilder treeResult = new StringBuilder(); St ...
- U-boot分析与移植(1)----bootloader分析
一.Boot Loader 概念 就是在操作系统内核运行之前运行的一段小程序.通过这段小程序,我们可以初始化硬件设备.建立内存空间的映射图,从而将系统的软硬件环境带到一个合适的状态,以便为最终调用操作 ...
- PHP字符串的处理(二)-字符串的格式化
1.字符串大小写的转换 strtoupper():将字符串全部转换为大写字母 strtolower():将字符串全部转换为小写字母 ucfirst():将字符串中的首字母转换为大写,其余字符不变 uc ...
- netty实现远程调用RPC功能
netty实现远程调用RPC功能 依赖 服务端功能模块编写 客户端功能模块编写 netty实现远程调用RPC功能 PRC的功能一句话说白了,就是远程调用其他电脑的api 依赖 <dependen ...
- openstack 租户ip 手动配置 openstack静态租户ip
作者:[吴业亮]云计算开发工程师 博客:http://blog.csdn.net/wylfengyujiancheng 1.综述: 在日常开发和生产环境中经常需要将OpenStack虚拟机配置一个静态 ...
- vue中使用markdown富文本,并在html页面中展示
想给自己的后台增加一个markdown编辑器,下面记录下引用的步骤 引入组件mavon-editor 官网地址:https://github.com/hinesboy/mavonEditor // 插 ...
- Vulkan Tutorial 03 理解Instance
操作系统:Windows8.1 显卡:Nivida GTX965M 开发工具:Visual Studio 2017 Creating an instance 与Vulkan打交道,通常的步骤是创建一个 ...
- RT2870移植到s3c2416后续验证无线…
我的无线网卡显示的事ra0,所以把下面的wlan0换成ra0即可:视自己的情况而定 1. 打开无线网卡电源 iwconfig wlan0 txpower on 2. 列出区域内的无线网络 iwlist ...
- 【原】Coursera—Andrew Ng机器学习—课程笔记 Lecture 6_Logistic Regression 逻辑回归
Lecture6 Logistic Regression 逻辑回归 6.1 分类问题 Classification6.2 假设表示 Hypothesis Representation6.3 决策边界 ...