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 ...
随机推荐
- map————两个数组的交集(2)
class Solution { public: vector<int> intersect(vector<int>& nums1, vector<int> ...
- vue如何每次打开子组件弹窗都进行初始化
:visible.sync 与 v-if同时使用即可.
- Python socket通信之FTP
Python中利用socket进行server端和client端通信是网络编程的基础,是最简单的传输范例. (懂网络的请自动跳过这一部分) 首先,要想通信,必须建立连接,建立连接的过程,需要clien ...
- python 网络编程 粘包问题
1.粘包现象 TCP粘包是指发送方发送的若干包数据到接收方接收时粘成一包,从接收缓冲区看,后一包数据的头紧接着前一包数据的尾. 粘包出现原因 使用了优化方法(Nagle算法),将多次间隔较小.数据 ...
- NYIST 860 又见01背包
又见01背包时间限制:1000 ms | 内存限制:65535 KB难度:3 描述 有n个重量和价值分别为wi 和 vi 的 物品,从这些物品中选择总重量不超过 W 的物品,求所有挑选方案中物品价值总 ...
- WinServer-AD操作常用powershell命令
powershell 操作AD常用命令 查询AD中默认的密码策略 Get-ADDefaultDomainPasswordPolicy 查询AD中密码永不过期的用户 Get-ADUser -Filter ...
- POJ 2888
思路挺清晰的.不过,我就是WA.不清楚为什么,很多数据都过了. 其实,一个置换后若有循环节个数为K,则N必定可以除以尽K.而K正好可以看成一个环.为什么呢?看前K个珠子,就是一个环,而后面的若干个K个 ...
- IntelliJ IDEA启动spring boot项目出现Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].TomcatEmbeddedContext[]]
IntelliJ IDEA启动spring boot项目出现Failed to start component [StandardEngine[Tomcat].StandardHost[localho ...
- HDOJ 2189 悼念512汶川大地震遇难同胞——来生一起走 【母函数】
题意:非常清楚不解释. 策略:如题. 就是个简单的母函数的改变. 这道题做了好久,才明确是那有毛病,还是理解的不够深刻. AC代码: #include<stdio.h> #include& ...
- hdu 2604 Queuing (矩阵高速幂)
Queuing Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...