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 ...
随机推荐
- 开源Android容器化框架Atlas开发者指南
Atlas是古希腊神话中的天神,是波士顿动力公司的机器人,借助搜索引擎,得以发现这个名词背后许许多多的含义.在手机淘宝,Atlas是一个扎根于Android客户端的一个组件化容器框架,相比神话中用手和 ...
- servlet中地址详细分析
path路径的写法 假设; 项目名为day01 webroot下存放静态文件demo.html 转发 request.getRequestDispatcherType("path" ...
- 工作流Activiti学习地址
http://blog.csdn.net/xnf1991/article/details/52610277
- bootstrap fileinput控件 + django后台上传、回显简单使用
一.控件下载:https://github.com/kartik-v/bootstrap-fileinput/ 官网:http://plugins.krajee.com/file-input 需要引入 ...
- 手写一个promise
Promise A+ 规范:https://promisesaplus.com/ 注:以下代码没有通过 promises-aplus-tests 的全部测试,但基本功能还是全的( 测试结果: 864 ...
- [读书笔记] R语言实战 (一) R语言介绍
典型数据分析的步骤: R语言:为统计计算和绘图而生的语言和环境 数据分析:统计学,机器学习 R的使用 1. 区分大小写的解释型语言 2. R语句赋值:<- 3. R注释: # 4. 创建向量 c ...
- 浅谈 Qt 布局那些事
Qt 布局那些事是本文介绍的内容,直接进入主题.GridLayout是一个非常强大的布局管理器,它可以实现很多复杂的布局,名字中暗示它将所有控件放置在类似网格的布局中.^__^GridLayout有两 ...
- typedef和define混用产生的错误
最近在写代码过程中,发现一个问题,编译总是过不去,报错如下: stdint.h::: error: duplicate 'unsigned' stdint.h::: error: 'long long ...
- JS侧边栏实现
<!DOCTYPE html> <html lang="en"> <style> </style> <head> < ...
- oracle 数据类型及函数
第一节:字符串类型及函数 字符类型分 3 种,char(n) .varchar(n).varchar2(n) : char(n)固定长度字符串,假如长度不足 n,右边空格补齐: varchar(n)可 ...