对短路变形POJ3615
Farmer John wants the cows to prepare for the county jumping competition, so Bessie and the gang are practicing jumping over hurdles. They are getting tired, though, so they want to be able to use as little energy as possible to jump over the hurdles.
Obviously, it is not very difficult for a cow to jump over several very short hurdles, but one tall hurdle can be very stressful. Thus, the cows are only concerned about the height of the tallest hurdle they have to jump over.
The cows' practice room has N (1 ≤ N ≤ 300) stations, conveniently labeled 1..N. A set of M (1 ≤ M ≤ 25,000) one-way paths connects pairs of stations; the paths are also conveniently labeled 1..M. Path i travels from station Si to station Ei and contains exactly one hurdle of height Hi (1 ≤ Hi ≤ 1,000,000). Cows must jump hurdles in any path they traverse.
The cows have T (1 ≤ T ≤ 40,000) tasks to complete. Task i comprises two distinct numbers, Ai and Bi (1 ≤ Ai ≤ N; 1 ≤ Bi ≤ N), which connote that a cow has to travel from station Ai to station Bi (by traversing over one or more paths over some route). The cows want to take a path the minimizes the height of the tallest hurdle they jump over when traveling from Ai to Bi . Your job is to write a program that determines the path whose tallest hurdle is smallest and report that height.
Input
* Line 1: Three space-separated integers: N, M, and T
* Lines 2..M+1: Line i+1 contains three space-separated integers: Si , Ei , and Hi
* Lines M+2..M+T+1: Line i+M+1 contains two space-separated integers that describe task i: Ai and Bi
Output
* Lines 1..T: Line i contains the result for task i and tells the smallest possible maximum height necessary to travel between the stations. Output -1 if it is impossible to travel between the two stations.
Sample Input
5 6 3
1 2 12
3 2 8
1 3 5
2 5 3
3 4 4
2 4 8
3 4
1 2
5 1
Sample Output
4
8
-1
寻找最短路中的最大权值
最短路径变形问题,由于有多组输入,直接用Floyd
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=1E4+;
const int INF=1e6+;
int arr[N][N]; void inint(int n){
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
arr[i][j]=arr[j][i]=INF;
}
arr[i][i]=;
}
} int main(){
int n,m,k;
// cin>>n>>m>>k;
scanf("%d%d%d",&n,&m,&k);
inint(n);
int x,y,z;
for(int i=;i<=m;i++){
// cin>>x>>y>>z;
scanf("%d%d%d",&x,&y,&z);
arr[x][y]=z;
} for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
for(int k=;k<=n;k++)
arr[j][k]=min(arr[j][k],max(arr[j][i],arr[i][k])); while(k--){
int a,b;
// cin>>a>>b;
scanf("%d%d",&a,&b);
if(arr[a][b]==INF){
puts("-1");
}
else {
printf("%d\n",arr[a][b]);
}
} return ;
}
对短路变形POJ3615的更多相关文章
- 最短路变形 poj3615&
问题: 牛要跨过一些障碍,希望以最小的体力跨过障碍,并且对于一条路径,只在乎其中最高的障碍. 输入N代表站点数,标记为1—N,输入M代表路径数,从站点S到E之间需要跨过高度为H的障碍. 输入T代表牛要 ...
- 最短路变形 poj3615& poj2263
问题: 牛要跨过一些障碍,希望以最小的体力跨过障碍,并且对于一条路径,只在乎其中最高的障碍. 输入N代表站点数,标记为1—N,输入M代表路径数,从站点S到E之间需要跨过高度为H的障碍. 输入T代表牛要 ...
- POJ-2253.Frogger.(求每条路径中最大值的最小值,最短路变形)
做到了这个题,感觉网上的博客是真的水,只有kuangbin大神一句话就点醒了我,所以我写这篇博客是为了让最短路的入门者尽快脱坑...... 本题思路:本题是最短路的变形,要求出最短路中的最大跳跃距离, ...
- POJ 3635 - Full Tank? - [最短路变形][手写二叉堆优化Dijkstra][配对堆优化Dijkstra]
题目链接:http://poj.org/problem?id=3635 题意题解等均参考:POJ 3635 - Full Tank? - [最短路变形][优先队列优化Dijkstra]. 一些口胡: ...
- POJ 3635 - Full Tank? - [最短路变形][优先队列优化Dijkstra]
题目链接:http://poj.org/problem?id=3635 Description After going through the receipts from your car trip ...
- POJ-1797Heavy Transportation,最短路变形,用dijkstra稍加修改就可以了;
Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K Description Background Hugo ...
- HDOJ find the safest road 1596【最短路变形】
find the safest road Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- HN0I2000最优乘车 (最短路变形)
HN0I2000最优乘车 (最短路变形) 版权声明:本篇随笔版权归作者YJSheep(www.cnblogs.com/yangyaojia)所有,转载请保留原地址! [试题]为了简化城市公共汽车收费系 ...
- 天梯杯 PAT L2-001. 紧急救援 最短路变形
作为一个城市的应急救援队伍的负责人,你有一张特殊的全国地图.在地图上显示有多个分散的城市和一些连接城市的快速道路.每个城市的救援队数量和每一条连接两个城市的快速道路长度都标在地图上.当其他城市有紧急求 ...
随机推荐
- 题解 P6249 【神帖】
这道题目我一看到就想起了经典题--关路灯 但是时间好像不太好搞啊! 我们可以枚举时间qwq 考虑 \(4\) 维 \(dp\) \(f_{i,j,t,0/1}\) 表示 \(zrl\) 看了第 \(i ...
- OpenCV-Python ORB(面向快速和旋转的BRIEF) | 四十三
目标 在本章中,我们将了解ORB的基础知识 理论 作为OpenCV的狂热者,关于ORB的最重要的事情是它来自" OpenCV Labs".该算法由Ethan Rublee,Vinc ...
- 谷歌开发者:看可口可乐公司是怎么玩转 TensorFlow 的?
在这篇客座文章中,可口可乐公司的 Patrick Brandt 将向我们介绍他们如何使用 AI 和 TensorFlow 实现无缝式购买凭证. 可口可乐的核心忠诚度计划于 2006 年以 MyCoke ...
- OS第1次实验报告:熟悉使用Linux命令和剖析ps命令
零.个人信息 姓名:陈韵 学号:201821121053 班级:计算1812 一.实验目的 熟悉Linux命令行操作 二.实验内容 使用man查询命令使用手册 基本命令使用 三.实验报告 1. 实验环 ...
- GIS中地图投影的定义
我国的基本比例尺地形图[1:5千.1:1万.1:2.5万.1:5万.1:10万.1:25万.1:50万.1:100万]中,大于等于50万的均采用高斯-克吕格投影[Gauss-Kruger]:小于50万 ...
- 【LeetCode】18.四数之和
题目描述 18. 四数之和 给定一个包含 n 个整数的数组 nums 和一个目标值 target,判断 nums 中是否存在四个元素 a,b,c 和 d ,使得 a + b + c + d 的值与 t ...
- tkinter gui控件回调和grid布局优化
0.引子 Tkinter 是 Python 的标准 GUI 库.Python 使用 Tkinter 可以快速的创建 GUI 应用程序.由于 Tkinter 是内置到 python 的安装包中.只要安装 ...
- GitHub 热点速览 Vol.14:周获 2k+ Vim 掀起三维编程风
作者:HelloGitHub-小鱼干 摘要(用于 公众号/博客园等地方)寓教于乐,应该是上周 Trending 的主题了,无论是被多人转发推荐的三维 Vim 项目 Vim³ 或者是流体运动的 WebG ...
- docker 搭建keepalived+nginx高可用
前言 最近工作 中 有用到keepalived,就想着 在 本地 搭建一套环境验证一下相关的功能.因为创建虚拟机比较麻烦,就借助 docker来搭建这样 一套 环境 ,顺带学习 巩固下docker的 ...
- 为什么scanf(" %c",&c)中%c前要空格?
空格确实不是必须的,但有了空格就可以忽略你输入的空格. ****例如:scanf(" %c" ,&c),你输入了' a'(a前面有个空格),a就能被c接受. 但控制符前如果 ...