题意:给定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. Linkin大话eclipse快捷键

    刚来这家公司的时候,作为菜鸟的我在帮别人调试代码的时候,有人说我快捷键使用的很熟悉. 呵呵,工欲善其事必先利其器,以下这些快捷键是最常用的也是要必须记住的. [Ctrl开头] Ctrl+1:快速修复 ...

  2. linkin大话设计模式--代理模式

    代理模式是一种应用非常广泛的设计模式,当客户端代码需要调用某个对象的时候,客户端并不关心是否可以准确的得到这个对象,他只要一个能够提供该功能的对象而已,此时我们就可以返回该对象的代理.总而言之,客户端 ...

  3. Storm Topology Parallelism

    Understanding the Parallelism of a Storm Topology What makes a running topology: worker processes, e ...

  4. GTID复制详解

    前言 GTID复制是MySQL 5.6后的新功能,在传统的方式里,主从切换后,需要找到binlog和POS点,然后执行命令change master to 指向新的主库.对于不是很有经验的人来说,往往 ...

  5. 【php】RBAC 管理权限

    用户   角色   权限 用户:张三 角色:管理员 权限:page/index1.php   能访问的页面

  6. 【Thinkphp 5】 如何引入extend拓展文件

    extend/maile/cc.php 文件目录 cc文件 必须要加上命名空间,如下 cc.php文件内容如下: namespace maile; //命名空间 maile是文件夹名称 class C ...

  7. GitHub For Beginners: Don’t Get Scared, Get Started

    It's 2013, and there's no way around it: you need to learn how to use GitHub.2 Why? Because it's a s ...

  8. oracle光标的使用

    以下plsql程序用的scott用户的dept,emp表. 1.光标的使用: --查询并打印员工的姓名名和薪水 /* 光标属性: %found %notfound */ set serveroutpu ...

  9. Struts2的配置和一个简单的例子

    Struts2的配置和一个简单的例子 笔记仓库:https://github.com/nnngu/LearningNotes 简介 这篇文章主要讲如何在 IntelliJ IDEA 中使用 Strut ...

  10. BZOJ 3990: [SDOI2015]排序 [搜索]

    3990: [SDOI2015]排序 题意:\(2^n\)的一个排列,给你n种操作,第i种把每\(2^{i-1}\)个数看成一段,交换任意两段.问是这个序列有序的操作方案数,两个操作序列不同,当且仅当 ...