题目链接: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. RocketMQ学习笔记(11)----RocketMQ的PushConsumer和PullConsumer

    1. PushConsumer 推,Broker主动向Consumer推消息,它Consumer的一种,应用通常向对象注册一个Listener接口,一旦接收到消息,Consumer对象立刻回调Lins ...

  2. CDR入门教程-CorelDRAW排版教程

    CorelDRAW是一个绘制矢量图,排版的软件.今天给大家带来一片教程就是关于排版的.大家快来试试吧. CDR下载:http://pan.baidu.com/s/1cD4buQ 步骤一:新建一个A4文 ...

  3. Java并发--线程安全策略

    1 不可变对象 用不可变对象保证线程安全,是相当于不让线程并发,逃避了并发. 不可变对象就是指一个类的实例化对象不可变.比如String类的实例 主要方法有: 将类声明为final 将所有成员声明为 ...

  4. 怎样验证layer.prompt输入的值为数值型???

    JS中使用isNaN()判断layer.prompt输入的值为数值型,代码如下: layer.prompt({ title: '设置比值', }, function(value, index, ele ...

  5. Pyhton学习——Day9

    #文件操作的其他方法 ###############################################################################文件的内置操作函数# ...

  6. node——读取文件中的路径问题

    前提 当前的js文件叫_dirnameandfilename.js和hello.txt同在G:\node练习文件夹下 还有一个_dirnameandfilename.js文件在i:/文件夹,但是i:/ ...

  7. ExcelToHtmlTable转换算法:将Excel转换成Html表格并展示(项目源码+详细注释+项目截图)

    功能概述 Excel2HtmlTable的主要功能就是把Excel的内容以表格的方式,展现在页面中.Excel的多个Sheet对应页面的多个Tab选项卡.转换算法的难点在于,如何处理行列合并,将Exc ...

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

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

  9. [Python Test] Use pytest fixtures to reduce duplicated code across unit tests

    In this lesson, you will learn how to implement pytest fixtures. Many unit tests have the same resou ...

  10. Eclipse 更新Android SDK后,新建项目出现appcompat_v7project的相关问题

    Eclipse 更新Android SDK后,新建项目出现各种问题.网上各种解决方式,搞了好久,总结一下. 1.出现error: Error retrieving parent for item: N ...