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 ...
随机推荐
- Elixir与编辑器安装
安装 Elixir 每个操作系统的安装说明可以在 elixir-lang.org 网站上 Installing Elixir 部分找到. 安装后你可以很轻松地确认所安装的版本. ~$:elixir - ...
- Codevs1062路由选择
/* #include<iostream> #include<cstdio> #include<cstring> #define MAXN 301 using na ...
- mysql delete语句不能用别名
在mysql数据库里运行delete语句 delete ’; 发现会报错: [Err] - You have an error in your SQL syntax; check the manual ...
- FIREDAC字段类型映射
为什么需要字段类型映射? 作为通用型数据引擎的FIREDAC或者UNIDAC,驱动某一种数据库以后,总有一些数据库的一些字段类型,数据引擎不能识别,反应到程序中就是数据引擎不能正确地读取该字段的值 . ...
- js上传文件研究
https://github.com/shengulong/javascript-file-upload
- 【转】 nginx重定向规则详细介绍
rewrite命令 nginx的rewrite相当于apache的rewriterule(大多数情况下可以把原有apache的rewrite规则加上引号就可以直接使用),它可以用在server,loc ...
- [转】 nginx rewrite规则
http://www.cnblogs.com/cgli/archive/2011/05/16/2047920.html 最近在VPS上尝试配置安装一个网站,VPS安装了LNMP(Linux+Nginx ...
- 制作ubuntu U盘安装盘
sudo dd if=ubuntu.iso of=/dev/sdb2 sudo syslinux /dev/sdb1
- 标C编程笔记day04 预处理、宏定义、条件编译、makefile、结构体使用
预处理:也就是包括须要的头文件,用#include<标准头文件>或#include "自己定义的头文件" 宏定义,如:#define PI 3.1415926 查看用宏 ...
- leetcode 刷题之路 68 Gas Station
There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You ...