poj 2253 dijkstra模板的使用
来源:互联网 发布:淘宝好评返现模板 编辑:程序博客网 时间:2024/06/09 14:57
需要对于模板进行修改
题意:给定N个点,求从1到2的所有路径中最大边长最小的解(最大值最小)
依据dijkstra单源最短路径的贪心思想
d[i] 表示从源点s到i所满足条件的值
那么 d[i] = min { max(d[k], e(k to i) ) }
松弛的时候
if d[i] > max(d[cur], edge)
d[i] = max(d[cur], edge)
注意数据类型int和double切换
#include <iostream>#include <vector>#include <map>#include <list>#include <set>#include <deque>#include <stack>#include <queue>#include <algorithm>#include <cmath>#include <cctype>#include <cstdio>#include <iomanip>#include <cmath>#include <cstdio>#include <iostream>#include <string>#include <sstream>#include <cstring>#include <queue>using namespace std;///宏定义const int INF = 10000000;const int MAXN = 310;const int maxn = MAXN;///全局变量 和 函数///struct Edge{int from;int to;double dist;};struct HeapNode{int u;double d;bool operator < (const HeapNode& rhs) const{return d > rhs.d;}};struct Dijkstra{int n, m; //点数和边数vector<Edge> edges; //边列表vector<int> G[maxn]; //每个结点出发的边编号bool done[maxn]; //是否已永久编号//int d[maxn]; //s到各个点的距离double d[maxn];int p[maxn]; //最短路中的上一条边 (打印结果用)void init(int n){this->n = n;for (int i = 0; i <= n; i++)G[i].clear();edges.clear();}void AddEdge(int from, int to, double dist){Edge tmp;tmp.from = from;tmp.to = to;tmp.dist = dist;edges.push_back(tmp);m = edges.size();G[from].push_back(m - 1);}void dijkstra(int s){priority_queue<HeapNode> Q;for (int i = 0; i <= n; i++)d[i] = INF;d[s] = 0;memset(done, 0, sizeof(done));HeapNode tmp;tmp.d = 0;tmp.u = s;Q.push(tmp);while (!Q.empty()){HeapNode x = Q.top();Q.pop();int u = x.u;if (done[u])continue;done[u] = true;for (int i = 0; i < G[u].size(); i++){Edge &e = edges[G[u][i]];if (d[e.to] > max(d[u], e.dist)){d[e.to] = max(d[u], e.dist);//p[e.to] = G[u][i];HeapNode temp;temp.d = d[e.to];temp.u = e.to;Q.push(temp);}}}}};int n;double posx[maxn];double posy[maxn];int main(){///变量定义int i, j;int cases = 1;while (1){scanf("%d", &n);if (n == 0)break;Dijkstra dij;dij.init(n);for (i = 1; i <= n; i++){cin >> posx[i] >> posy[i];}for (i = 1; i <= n; i++){for (j = 1; j <= n; j++){if (i != j){double dist = sqrt( (posx[i] - posx[j]) * (posx[i] - posx[j]) + (posy[i] - posy[j]) * (posy[i] - posy[j]) );dij.AddEdge(i, j, dist);//dij.AddEdge(j, i, dist);}}}dij.dijkstra(1);double ans = dij.d[2];printf("Scenario #%d\n", cases++);printf("Frog Distance = %.3f\n", ans);printf("\n");}///结束return 0;}
- poj 2253 dijkstra模板的使用
- 朴素的dijkstra模板
- dijkstra的算法模板
- 最短路模板:使用priority_queue实现的Dijkstra算法
- poj 2387 最短路径 **dijkstra模板
- POJ 1502 MPI Maelstrom (Dijkstra 模板题)
- POJ 1502:MPI Maelstrom Dijkstra模板题
- poj-1797-Heavy Transportation dijkstra 水模板
- poj 3255 次短路+dijkstra+挑战模板
- poj 2253 - Frogger --- dijkstra
- poj 2253 : Frogger (dijkstra)
- poj 2253 dijkstra
- POJ 2253 Dijkstra
- poj 2253 Frogger [dijkstra]
- POJ 2253 Dijkstra变形
- poj 2253 Dijkstra
- poj 2253 Frogger 【dijkstra】
- POJ. 2253 Frogger (Dijkstra )
- LoadRunner测试场景执行过程(七)
- Android 编程中几个 常用的字符串转数字函数
- 使用ImageView引起Missing contentDescription attribute on image的问题
- Delphi应用程序的调试(八)事件日志窗口和模块窗口
- hdu 1143 Tri Tiling
- poj 2253 dijkstra模板的使用
- Delphi应用程序的调试(九)调试技术
- 以金山界面库(openkui)为例思考和分析界面库的设计和实现——代码结构(完)
- 解决VS2005或2008中新建VC++时的错误
- 准提神咒
- Delphi应用程序的调试(十)调试器选项
- VS2010双击选中或者光标选中代码时频繁崩溃问题
- android电量管理
- 已知前序和中序求后序