题目链接:https://cn.vjudge.net/problem/POJ-2253

题意

一只Forg需要从节点1走到节点n

现要找一条各个间隔最小的路径

问间隔最小是多少

思路

用dijsktra就好

查找间隔最小的路径

  1. 注意浮点数的比较

代码

#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查找间隔最小的路径的更多相关文章

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

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

  2. 最短路(Floyd_Warshall) POJ 2253 Frogger

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

  3. POJ. 2253 Frogger (Dijkstra )

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

  4. POJ 2253 Frogger(dijkstra 最短路

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

  5. POJ 2253 ——Frogger——————【最短路、Dijkstra、最长边最小化】

    Frogger Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Stat ...

  6. poj 2253 Frogger 最小瓶颈路(变形的最小生成树 prim算法解决(需要很好的理解prim))

    传送门: http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissi ...

  7. POJ 2253 Frogger Floyd

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

  8. POJ 2253 Frogger

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

  9. poj 2253 Frogger (dijkstra最短路)

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

随机推荐

  1. Pyhton学习——Day4

    '''y=2*x+1x=3y->7x=3y->7'''# def test(x):# '''# 2*x+1# :param x:整形数字# :return: 返回计算结果# '''# y= ...

  2. 12、Camel: Content-Aware and Meta-path Augmented Metric Learning for Author Identification----作者识别

    摘自:https://blog.csdn.net/me_yundou/article/details/80459341 具体看上面链接 一.摘要: 这篇文章主要介绍的是作者识别(author iden ...

  3. BZOJ 3697/3127 采药人的路径 (点分治)

    题目大意: 从前有一棵无向树,树上边权均为$0$或$1$,有一个采药人,他认为如果一条路径上边权为$0$和$1$的边数量相等,那么这条路径阴阳平衡.他想寻找一条合法的采药路径,保证阴阳平衡.然后他发现 ...

  4. tomcat闪退无法启动 the catalina_home environment variable is not defined correctly this environment variable is needed to run this program

    未成功配置CATALINA_HOME 1.计算机>属性>环境变量, 新建环境变量.变量名为CATALINA_HOME ,变量值tomcat的解压目录,注意后面不用多加“\”或者“;” 2. ...

  5. 20130910.Windows上安装和配置MongoDB

    官方文档:http://docs.mongodb.org/manual/tutorial/ 1.下载软件 http://www.mongodb.org/downloads 2.解压 解压后进入bin目 ...

  6. STM32 使用Cubemx 建一个USB(HID)设备下位机,实现数据收发

    这里我主要说一下如何做一个USB下位机,这里主要分3部分:1.建立工程:2.添加报文描述符:3.数据的传输.这里就不讲USB的理论知识了,有想要了解的自行百度一下就可以了. 建立工程:工程建立参考:h ...

  7. JS冒泡排序方法

  8. 2015 Multi-University Training Contest 3 hdu 5325 Crazy Bobo

    Crazy Bobo Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total ...

  9. Http请求和相应模式(B/S)(1)

    B/S模式 服务器端的接受数据 :浏览器端 表单格式 <form></form> GET:请求方式, /index.html  Web浏览器上的资源路径 uname=bjxt& ...

  10. HDU 4303 Contest 1

    说实话,挺复杂的一道题. 我采用栈的方式,DFS在搜索完一个节点的所有子结点后,通过排序,加快计算该结点所有可能的路径:子结点与子结点的连通,子结点与父结点的连通,通过父结点与各祖先结点的连通.同时记 ...