POJ - 2253 Frogger 单源最短路
题意:给定n个点的坐标,问从第一个点到第二个点的最小跳跃范围。d(i)表示从第一个点到达第i个点的最小跳跃范围.
AC代码
#include <cstdio>
#include <cmath>
#include <cctype>
#include <algorithm>
#include <cstring>
#include <utility>
#include <string>
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define eps 1e-10
#define inf 0x3f3f3f3f
#define PI pair<int, int>
typedef long long LL;
const int maxn = 200 + 5;
int d[maxn], vis[maxn];
struct node{
int x, y;
}a[maxn];
struct HeapNode{
int d, u;
HeapNode() {}
HeapNode(int d, int u):d(d), u(u) {}
bool operator < (const HeapNode &p) const {
return d > p.d;
}
};
void dijkstra(int s, int n) {
priority_queue<HeapNode>q;
memset(d, inf, sizeof(d));
d[0] = 0;
memset(vis, 0, sizeof(vis));
q.push(HeapNode(0, 0));
while(!q.empty()) {
HeapNode p = q.top(); q.pop();
int u = p.u;
if(vis[u]) continue;
vis[u] = 1;
for(int i = 0; i < n; ++i) {
if(u == i) continue;
int dis = (a[u].x - a[i].x)*(a[u].x - a[i].x) + (a[u].y - a[i].y)*(a[u].y - a[i].y);
dis = max(dis, d[u]);
if(d[i] > dis) {
d[i] = dis;
q.push(HeapNode(d[i], i));
}
}
}
}
int main() {
int n, kase = 1;
while(scanf("%d", &n) == 1 && n) {
for(int i = 0; i < n; ++i) scanf("%d%d", &a[i].x, &a[i].y);
dijkstra(0, n);
printf("Scenario #%d\n", kase++);
printf("Frog Distance = %.3f\n\n", sqrt((double)d[1]));
}
return 0;
}
如有不当之处欢迎指出!
POJ - 2253 Frogger 单源最短路的更多相关文章
- POJ 2253 Frogger(dijkstra 最短路
POJ 2253 Frogger Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fion ...
- poj 2253 Frogger (dijkstra最短路)
题目链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
- POJ 2253 - Frogger - [dijkstra求最短路]
Time Limit: 1000MS Memory Limit: 65536K Description Freddy Frog is sitting on a stone in the middle ...
- 最短路(Floyd_Warshall) POJ 2253 Frogger
题目传送门 /* 最短路:Floyd算法模板题 */ #include <cstdio> #include <iostream> #include <algorithm& ...
- POJ 2253 Frogger ,poj3660Cow Contest(判断绝对顺序)(最短路,floyed)
POJ 2253 Frogger题目意思就是求所有路径中最大路径中的最小值. #include<iostream> #include<cstdio> #include<s ...
- POJ. 2253 Frogger (Dijkstra )
POJ. 2253 Frogger (Dijkstra ) 题意分析 首先给出n个点的坐标,其中第一个点的坐标为青蛙1的坐标,第二个点的坐标为青蛙2的坐标.给出的n个点,两两双向互通,求出由1到2可行 ...
- 最短路模板(Dijkstra & Dijkstra算法+堆优化 & bellman_ford & 单源最短路SPFA)
关于几个的区别和联系:http://www.cnblogs.com/zswbky/p/5432353.html d.每组的第一行是三个整数T,S和D,表示有T条路,和草儿家相邻的城市的有S个(草儿家到 ...
- [ACM_图论] Domino Effect (POJ1135 Dijkstra算法 SSSP 单源最短路算法 中等 模板)
Description Did you know that you can use domino bones for other things besides playing Dominoes? Ta ...
- 用scheme语言实现SPFA算法(单源最短路)
最近自己陷入了很长时间的学习和思考之中,突然发现好久没有更新博文了,于是便想更新一篇. 这篇文章是我之前程序设计语言课作业中一段代码,用scheme语言实现单源最段路算法.当时的我,花了一整天时间,学 ...
随机推荐
- Nginx的安装(笔记)
0, 先决条件Nginx 依赖 zlib zlib-devel gcc-c++ libtool openssl openssl-devel pcre安装命令:yum -y install make z ...
- ssh 设置私钥实现两台linux主机无密码访问
在服务器主机上(称为A主机) 创建公钥与私钥: ssh-keygen -t rsa 一路回车,如果想设置密码短语,在提示 passphrase 的时候设置密码短语 查看生成的公钥及私钥: ls ~/. ...
- Oracle 12cR1 RAC 在VMware Workstation上安装(中)—图形界面安装
Oracle 12cR1 RAC 在VMware Workstation上安装(中)—图形界面安装 1.1 图形界面安装 1.1.1 安装GRID 安装日志:/u01/app/oraInvento ...
- BZOJ 3998: [TJOI2015]弦论 [后缀自动机 DP]
3998: [TJOI2015]弦论 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 2152 Solved: 716[Submit][Status] ...
- 测试SM图床
- 监督学习:随机梯度下降算法(sgd)和批梯度下降算法(bgd)
线性回归 首先要明白什么是回归.回归的目的是通过几个已知数据来预测另一个数值型数据的目标值. 假设特征和结果满足线性关系,即满足一个计算公式h(x),这个公式的自变量就是已知的数据x,函数值h(x)就 ...
- python爬虫登录
python3 urllib.request 网络请求操作 http://www.cnblogs.com/cocoajin/p/3679821.html python实现 爬取twitter用户姓名 ...
- iOS开发中UIPopoverController的使用详解
这篇文章主要介绍了iOS开发中UIPopoverController的使用,代码基于传统的Objective-C,需要的朋友可以参考下 一.简单介绍 1.什么是UIPopoverController ...
- Go学习笔记01-语言
1.1 变量 Go 是静态类型语言,不能在运行期改变变量类型.使用关键字 var 定义变量,自动初始化为零值.如果提供初始化值,可省略变量类型,由编译器自动推断. var x int var f fl ...
- macbook air扩展显示器全屏滑动怎样不一起滑动?
macbook air 外接了一个显示器(扩展),当我有多个桌面时,用手指滑动触控板切换桌面时,扩展屏幕也跟着切换桌面有什么办法能让我在切换主屏幕桌面的时候,扩展屏幕保持不动呢?上周还好好的,昨晚关机 ...