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语言实现单源最段路算法.当时的我,花了一整天时间,学 ...
随机推荐
- Windows核心编程&线程
1. 线程上下文:线程内核对象保存线程上一次执行时的CPU寄存器状态 2. 线程上下文切换 3. windows操作系统为抢占式多线程操作系统,系统可以在任何时刻停止一个线程而另行调度另外一个线程.我 ...
- nodejs爬虫笔记(五)---利用nightmare模拟点击下一页
目标 以腾讯滚动新闻为例,利用nightmare模拟点击下一页,爬取所有页面的信息.首先得感谢node社区godghdai的帮助,开始接触不太熟悉nightmare,感觉很高大上,自己写代码的时候问题 ...
- awk使用正则精确匹配
[root@localhost home]# cat file 5001][YRSD5-1][YRSD5-1-2][0203008400028411] 010102 5001][YRSD7-1][YR ...
- hdu3507 Print Article
Print Article Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) P ...
- 模型的元数据Meta -- Django从入门到精通系列教程
该系列教程系个人原创,并完整发布在个人官网刘江的博客和教程 所有转载本文者,需在顶部显著位置注明原作者及www.liujiangblog.com官网地址. Python及Django学习QQ群:453 ...
- Sizeof的三种作用
一.计算常量占用的字节数 例如:int num=sizeof(10); printf("%i",num); 二.计算变量占用的字节数 例如:int num2=3; int resu ...
- c#代码启动任务管理器的几种方法
1.直接启动 ProcessStartInfo info = new ProcessStartInfo(); info.FileName = Path.Combine(Environment.GetE ...
- spring boot + vue + element-ui全栈开发入门——前端列表页面开发
一.页面 1.布局 假设,我们要开发一个会员列表的页面. 首先,添加vue页面文件“src\pages\Member.vue” 参照文档http://element.eleme.io/#/zh-CN ...
- 转载-Oracle ORACLE的sign函数和DECODE函数
原文地址:http://www.cnblogs.com/BetterWF/archive/2012/06/12/2545829.html 转载以备用 比较大小函数 sign 函数语法:sign(n) ...
- Laravel (5.5.33) 加载过程(一)
说明: 由于公司项目使用Laravel 框架 也是第一次接触此框架 作为一个新手 记录使用过程的一些事情 以及对于框架源码分析的记录 整理自己的思路 也希望对大家有帮助 如果那里不对的地方 ...