题意:给定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 单源最短路的更多相关文章

  1. POJ 2253 Frogger(dijkstra 最短路

    POJ 2253 Frogger Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fion ...

  2. poj 2253 Frogger (dijkstra最短路)

    题目链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissi ...

  3. POJ 2253 - Frogger - [dijkstra求最短路]

    Time Limit: 1000MS Memory Limit: 65536K Description Freddy Frog is sitting on a stone in the middle ...

  4. 最短路(Floyd_Warshall) POJ 2253 Frogger

    题目传送门 /* 最短路:Floyd算法模板题 */ #include <cstdio> #include <iostream> #include <algorithm& ...

  5. POJ 2253 Frogger ,poj3660Cow Contest(判断绝对顺序)(最短路,floyed)

    POJ 2253 Frogger题目意思就是求所有路径中最大路径中的最小值. #include<iostream> #include<cstdio> #include<s ...

  6. POJ. 2253 Frogger (Dijkstra )

    POJ. 2253 Frogger (Dijkstra ) 题意分析 首先给出n个点的坐标,其中第一个点的坐标为青蛙1的坐标,第二个点的坐标为青蛙2的坐标.给出的n个点,两两双向互通,求出由1到2可行 ...

  7. 最短路模板(Dijkstra & Dijkstra算法+堆优化 & bellman_ford & 单源最短路SPFA)

    关于几个的区别和联系:http://www.cnblogs.com/zswbky/p/5432353.html d.每组的第一行是三个整数T,S和D,表示有T条路,和草儿家相邻的城市的有S个(草儿家到 ...

  8. [ACM_图论] Domino Effect (POJ1135 Dijkstra算法 SSSP 单源最短路算法 中等 模板)

    Description Did you know that you can use domino bones for other things besides playing Dominoes? Ta ...

  9. 用scheme语言实现SPFA算法(单源最短路)

    最近自己陷入了很长时间的学习和思考之中,突然发现好久没有更新博文了,于是便想更新一篇. 这篇文章是我之前程序设计语言课作业中一段代码,用scheme语言实现单源最段路算法.当时的我,花了一整天时间,学 ...

随机推荐

  1. JavaScript高级编程小结

    Undefined 对未初始化的变量执行typeof操作符会返回undefined值,而对未声明的变量执行typeof操作符同样也会返回undefined var message; console.l ...

  2. Git初入

    Git记录 使用git 也有一段时间了, git的入门级了解也就不再多说, 但平常使用中, 仍然会遇到很多问题, 在此记录一二. 在查资料的过程中, 发现了两个比较好的资料: 特别是第二个, 相当详细 ...

  3. ng机器学习视频笔记(二) ——梯度下降算法解释以及求解θ

    ng机器学习视频笔记(二) --梯度下降算法解释以及求解θ (转载请附上本文链接--linhxx)   一.解释梯度算法 梯度算法公式以及简化的代价函数图,如上图所示. 1)偏导数 由上图可知,在a点 ...

  4. 用Lua定制Redis命令

    * { color: #3e3e3e } body { font-family: "Helvetica Neue", Helvetica, "Hiragino Sans ...

  5. 【原创】POI 生成Excel文件并下载

    ι 版权声明:本文为博主原创文章,未经博主允许不得转载. 效果图: 实现 1.在pom中添加依赖: <!-- https://mvnrepository.com/artifact/org.apa ...

  6. 用swing做一个简单的正则验证工具

    直接上代码吧,因为我对swing也不熟悉,照着API一点点拼出来的. import java.awt.event.ActionEvent; import java.awt.event.ActionLi ...

  7. Directx3d绘制包围体并控制光照效果

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  8. 解决mysql、vsftp远程连接速度慢的问题

    以 centOS 6.3(其他操作系统类似,同样适用)说明: 当我们的服务都配置正常的情况下,有时会出现连接速度慢而导致连接失败的问题 问题分析:这些情况一般都是DNS解析惹的祸 mysql连接速度慢 ...

  9. Spring对远程服务的支持

    Java程序有以下的远程调用技术选择: 远程过程调用(RPC)是同步的,客户端在服务器端返回结果之前将一直被阻塞. 各种技术适用的场景如下: 典型的RMI开发的过程如下: 定义一个接口,用于客户端和服 ...

  10. BZOJ 1927: [Sdoi2010]星际竞速 [上下界费用流]

    1927: [Sdoi2010]星际竞速 题意:一个带权DAG,每个点恰好经过一次,每个点有曲速移动到他的代价,求最小花费 不动脑子直接上上下界费用流过了... s到点连边边权为曲速的代价,一个曲速移 ...