POJ-2253 Frogger dijsktra查找间隔最小的路径
题目链接:https://cn.vjudge.net/problem/POJ-2253
题意
一只Forg需要从节点1走到节点n
现要找一条各个间隔最小的路径
问间隔最小是多少
思路
用dijsktra就好
查找间隔最小的路径
- 注意浮点数的比较
代码
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
using namespace std;
const int maxn=200, INF=0x3f3f3f3f;
const double eps=1e-6;
typedef pair<double, int> Pair;
struct Node{
int x, y;
Node(int x=0, int y=0):x(x), y(y) {}
}node[maxn+5];
struct Edge{
int from, to;
Edge(int from=0, int to=0):from(from), to(to) {}
};
vector<Edge> edges;
vector<int> G[maxn+5];
double dist[maxn+5];
void addEdge(int from, int to){
edges.push_back(Edge(from, to));
G[from].push_back(edges.size()-1);
G[to].push_back(edges.size()-1);
}
inline bool equal(const double &a, const double &b){
return (a-b<=eps && b-a<=eps);
}
inline double Dis(const int &a, const int &b){
return sqrt((node[a].x-node[b].x)*(node[a].x-node[b].x)+
(node[a].y-node[b].y)*(node[a].y-node[b].y));
}
double dij(void){
for (int i=0; i<=maxn; i++) dist[i]=INF;
priority_queue<Pair, vector<Pair>, greater<Pair> > que;
que.push(Pair(0, 1)); dist[1]=0;
while (que.size()){
Pair x=que.top(); que.pop();
if (!equal(x.first, dist[x.second])) continue;
int from=x.second;
for (int i=0; i<G[from].size(); i++){
Edge &e=edges[G[from][i]];
int to=(e.to==from)?e.from:e.to;
double dis=Dis(to, from), mdis=max(dist[from], dis);
if (dist[to]<mdis || equal(dist[to], mdis)) continue;
dist[to]=mdis;
que.push(Pair(dist[to], to));
}
}return dist[2];
}
int main(void){
int n, cnt=1, x, y;
while (scanf("%d", &n)==1 && n){
for (int i=1; i<=n; i++){
scanf("%d%d", &x, &y);
node[i]=Node(x, y);
for (int j=1; j<i; j++) addEdge(i, j);
}
printf("Scenario #%d\nFrog Distance = %.3f\n\n", cnt++, dij());
}
return 0;
}
| Time | Memory | Length | Lang | Submitted |
|---|---|---|---|---|
| 16ms | 1476kB | 1878 | G++ | 2018-05-23 15:31:25 |
POJ-2253 Frogger dijsktra查找间隔最小的路径的更多相关文章
- POJ 2253 Frogger ,poj3660Cow Contest(判断绝对顺序)(最短路,floyed)
POJ 2253 Frogger题目意思就是求所有路径中最大路径中的最小值. #include<iostream> #include<cstdio> #include<s ...
- 最短路(Floyd_Warshall) POJ 2253 Frogger
题目传送门 /* 最短路:Floyd算法模板题 */ #include <cstdio> #include <iostream> #include <algorithm& ...
- POJ. 2253 Frogger (Dijkstra )
POJ. 2253 Frogger (Dijkstra ) 题意分析 首先给出n个点的坐标,其中第一个点的坐标为青蛙1的坐标,第二个点的坐标为青蛙2的坐标.给出的n个点,两两双向互通,求出由1到2可行 ...
- 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、最长边最小化】
Frogger Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Stat ...
- poj 2253 Frogger 最小瓶颈路(变形的最小生成树 prim算法解决(需要很好的理解prim))
传送门: http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
- POJ 2253 Frogger Floyd
原题链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
- POJ 2253 Frogger
题目链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
- poj 2253 Frogger (dijkstra最短路)
题目链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
随机推荐
- Java中使用MD5加密的简单实现
import java.math.BigInteger; import java.security.MessageDigest; import java.security.NoSuchAlgorith ...
- jq——css类
1 addClass(classname) 添加类 <script type="text/javascript"> $("input").clic ...
- Django Views Decorator
Django的试图函数的装饰器主要有: HTTP请求方法 条件视图处理 GZip压缩 改变页眉 缓存 官网文档 HTTP请求方法 该装饰器是设置允许访问HTTP协议的方法,装饰器在django.vie ...
- django patch 解决 ["'15428560000' value has an invalid format. It must be in YYYY-MM-DD HH:MM[:ss[.uuuuuu]][TZ] format."]
__init__.py import datetime from django.apps import AppConfig from django.db.models.fields import Da ...
- [luogu] P4155 [SCOI2015]国旗计划(贪心)
P4155 [SCOI2015]国旗计划 题目描述 A 国正在开展一项伟大的计划 -- 国旗计划.这项计划的内容是边防战士手举国旗环绕边境线奔袭一圈.这项计划需要多名边防战士以接力的形式共同完成,为此 ...
- (转载)spring 之间的远程调用-Spring Http调用的实现
原文:https://www.cnblogs.com/lewisat/p/6132082.html 1:Spring Http设计思想 最近在研究公司自己的一套rpc远程调用框架,看到其内部实现的设计 ...
- oracle 数据类型及函数
第一节:字符串类型及函数 字符类型分 3 种,char(n) .varchar(n).varchar2(n) : char(n)固定长度字符串,假如长度不足 n,右边空格补齐: varchar(n)可 ...
- open函数详解
转载:https://www.cnblogs.com/frank-yxs/p/5925574.html open函数用来在进程中打开文件,如果成功则返回一个文件描述符fd. ============= ...
- POJ 3744
矩阵快速乘求概率,不难.但有注意的一点是,一定要注意地雷连着的情况,一旦出现两个雷相邻,就必定为0了. #include <iostream> #include <algorithm ...
- VC6.0VB6.0 Scratch等软件
VC6.0VB6.0 Scratch等软件 http://pan.baidu.com/s/1nv4hJrb