POJ2253 Frogger —— 最短路变形
题目链接:http://poj.org/problem?id=2253
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 49409 | Accepted: 15729 |
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
Source
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <set>
#define rep(i,a,n) for(int (i) = a; (i)<=(n); (i)++)
#define ms(a,b) memset((a),(b),sizeof((a)))
using namespace std;
typedef long long LL;
const double EPS = 1e-;
const int INF = 2e9;
const LL LNF = 9e18;
const int MOD = 1e9+;
const int MAXN = 1e3+; int n; struct edge
{
double w;
int to, next;
}edge[MAXN*MAXN];
int cnt, head[MAXN]; void addedge(int u, int v, double w)
{
edge[cnt].to = v;
edge[cnt].w = w;
edge[cnt].next = head[u];
head[u] = cnt++;
} void init()
{
cnt = ;
memset(head, -, sizeof(head));
} double dis[MAXN];
bool vis[MAXN];
void dijkstra(int st)
{
memset(vis, , sizeof(vis));
for(int i = ; i<=n; i++)
dis[i] = (i==st?:INF); for(int i = ; i<=n; i++)
{
int k;
double minn = INF;
for(int j = ; j<=n; j++)
if(!vis[j] && dis[j]<minn)
minn = dis[k=j]; vis[k] = ;
for(int j = head[k]; j!=-; j = edge[j].next) //dis[i]为经过i点的路径中边权最大值的最小值。
if(!vis[edge[j].to])
dis[edge[j].to] = min(dis[edge[j].to], max(dis[k], edge[j].w) );
}
} int x[MAXN], y[MAXN];
int main()
{
int kase = ;
while(scanf("%d", &n) && n)
{
init();
for(int i = ; i<=n; i++)
scanf("%d%d", &x[i], &y[i]);
for(int i = ; i<=n; i++)
for(int j = ; j<=n; j++)
addedge(i, j, sqrt( (x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])) ); dijkstra();
printf("Scenario #%d\n", ++kase);
printf("Frog Distance = %.3f\n\n", dis[]);
}
}
POJ2253 Frogger —— 最短路变形的更多相关文章
- POJ 2253 Frogger ( 最短路变形 || 最小生成树 )
题意 : 给出二维平面上 N 个点,前两个点为起点和终点,问你从起点到终点的所有路径中拥有最短两点间距是多少. 分析 : ① 考虑最小生成树中 Kruskal 算法,在建树的过程中贪心的从最小的边一个 ...
- B - Frogger 最短路变形('最长路'求'最短路','最短路'求'最长路')
http://poj.org/problem?id=2253 题目大意: 有一只可怜没人爱的小青蛙,打算去找他的女神青蛙姐姐,但是池塘水路不能走,所以只能通过蹦跶的形式到达目的地,问你从小青蛙到青蛙姐 ...
- POJ 2253 Frogger -- 最短路变形
这题的坑点在POJ输出double不能用%.lf而要用%.f...真是神坑. 题意:给出一个无向图,求节点1到2之间的最大边的边权的最小值. 算法:Dijkstra 题目每次选择权值最小的边进行延伸访 ...
- POJ2253 frogger 最短路 floyd
#include<iostream>#include<algorithm>#include<stdio.h>#include<string.h>#inc ...
- POJ-2253.Frogger.(求每条路径中最大值的最小值,最短路变形)
做到了这个题,感觉网上的博客是真的水,只有kuangbin大神一句话就点醒了我,所以我写这篇博客是为了让最短路的入门者尽快脱坑...... 本题思路:本题是最短路的变形,要求出最短路中的最大跳跃距离, ...
- POJ 3635 - Full Tank? - [最短路变形][手写二叉堆优化Dijkstra][配对堆优化Dijkstra]
题目链接:http://poj.org/problem?id=3635 题意题解等均参考:POJ 3635 - Full Tank? - [最短路变形][优先队列优化Dijkstra]. 一些口胡: ...
- POJ 3635 - Full Tank? - [最短路变形][优先队列优化Dijkstra]
题目链接:http://poj.org/problem?id=3635 Description After going through the receipts from your car trip ...
- POJ-1797Heavy Transportation,最短路变形,用dijkstra稍加修改就可以了;
Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K Description Background Hugo ...
- HDOJ find the safest road 1596【最短路变形】
find the safest road Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
随机推荐
- .net面试题汇总-第二篇
本篇主要关注下,.net面试题中经常用的算法问题 1.有一群猴子,它们每天要吃桃子,它们第一天吃的数量是总量的一半再多一个,第二天吃的是第一天剩下的一半再多一个,第三天吃的是第二天剩下的一半多一个,以 ...
- leetcode 331. Verify Preorder Serialization of a Binary Tree
传送门 331. Verify Preorder Serialization of a Binary Tree My Submissions QuestionEditorial Solution To ...
- css3 nth-child 与 nth-of-type 的区别
by zhangxinxu from http://www.zhangxinxu.com本文地址:http://www.zhangxinxu.com/wordpress/?p=1709 一.深呼吸,直 ...
- android layout
android的视图分为两类,一类是布局,另一个类是控件 一.LinearLayout(线性布局) 最常用布局之一,线性布局的特性是每添加一个控件默认会在上个控件的下面占一行. <LinearL ...
- HDU 4341 Gold miner(分组背包)
题目链接 Gold miner 目标是要在规定时间内获得的价值总和要尽可能大. 我们先用并查集把斜率相同的物品分在同一个组. 这些组里的物品按照y坐标的大小升序排序. 如果组内的一个物品被选取了,那该 ...
- Jetson TK1 一:调整屏幕分辨率
先点击分辨率调整的那个对话框,就是1024×768之类的那个,选定一个分辨率,我选的是1366x768(16:9)的那个,然后连续按7下tab按键,然后回车,然后再点击弹出的选项右边一个就能保存了.
- pandaboard用wifi时打不开网页
不可以手动修改/etc/resolv.conf,因为重启会被自动清空(raspberry pi 可以) 修改 resolvconf服务的配置文件: /etc/resolvconf/resolv.con ...
- 转:c++ 11 新特性
声 明:本文源自 Danny Kalev 在 2011 年 6 月 21 日发表的<The Biggest Changes in C++11(and Why You Should Care)&g ...
- 【Todo】UDP P2P打洞原理
参考以下两篇文章: https://my.oschina.net/ososchina/blog/369206 http://m.blog.csdn.net/article/details?id=666 ...
- PCA主成分分析Python实现
作者:拾毅者 出处:http://blog.csdn.net/Dream_angel_Z/article/details/50760130 Github源代码:https://github.com/c ...