POJ3615 跨栏最大高度(多源最短路径)
来源:互联网 发布:腾讯云计算数据中心 编辑:程序博客网 时间:2024/03/29 19:24
有N个地点,它们之间存在M条单向路径,每条路径中间有一个栏。现在给定一些起点和终点,要求找出它们之间的一条路径,使路径经过的栏的高度的最大值最小。
简单的多源最短路径,把路径值变成经过的最大高度值,用FLOYD算法更新每对点之间的最大高度值,然后对于每个起点和终点输出它们之间的最大高度值,若无法从起点到达终点,则输出-1。
#include <iostream>#include <cstdio>#include <algorithm>using namespace std;const int N = 305;const int MAX = 0xfffffff;int n, m, t;int edge[N][N];void floyd(){int tmax;for (int k = 1; k <= n; ++k){for (int i = 1; i <= n; ++i){for (int j = 1; j <= n; ++j){int tmax = edge[i][k] > edge[k][j] ? edge[i][k] : edge[k][j];if (tmax < edge[i][j]) edge[i][j] = tmax;}}}}int main(){int beg, end, dis;scanf("%d%d%d", &n, &m, &t);for (int i = 1; i <= n; ++i){for (int j = 1; j <= n; ++j){edge[i][j] = MAX;}}for (int i = 0; i < m; ++i){scanf("%d%d%d", &beg, &end, &dis);edge[beg][end] = dis;}floyd();for (int i = 0; i < t; ++i){scanf("%d%d", &beg, &end);if (edge[beg][end] == MAX) printf("-1\n");else printf("%d\n", edge[beg][end]);}return 0;}
- POJ3615 跨栏最大高度(多源最短路径)
- poj3615
- poj3615
- poj3615
- poj3615
- POJ3615
- POJ3615
- 跨栏运动(hurding)
- 最大高度差(暴力/DP/RMQ)
- Scratch for pcDuino 课例(三)—— 跨栏游戏
- bzoj 1641: [Usaco2007 Nov]Cow Hurdles 奶牛跨栏(floyd)
- bzoj1641 [Usaco2007 Nov]Cow Hurdles 奶牛跨栏(Floyd)
- 跨栏定律
- 跨栏定律
- 跨栏定律
- Panel 最大高度
- ZOJ 1093 最大高度
- 最大高度的listview
- tomcat6.0绿色版 环境变量配置
- div+css小案例
- python笔记:简单的查找与排序算法
- java中对字符串的一些简单操作
- 使用postmessage发送自定义消息
- POJ3615 跨栏最大高度(多源最短路径)
- dbus 例程
- 打印更精准激光3D打印机问世
- Shell Script 提取文件名和文件扩展名的方法
- C++的性能检测
- 好书
- 【转】C++内存分配方式详解——堆、栈、自由存储区、全局/静态存储区和常量存储区
- C++中关于写日志文件Log的方法
- jquery分页插件jquery.tablesorter.pager.js,点击下一页跳到后两页问题