洛谷P2888 [USACO07NOV]牛栏Cow Hurdles
题目描述
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.
奶牛们为了比赛要刻苦训练跳木桩。现在有n个木桩,并知道其中m对木桩的高度差。问奶牛们能从木桩u跳到木桩v,最少的跳跃高度是多少?
输入输出格式
输入格式:
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
输出格式:
- 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.
输入输出样例
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
4
8
-1
裸floyd
有个坑点是,跳柱子还神tm是单向的……
/*by SilverN*/
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
using namespace std;
const int mxn=;
int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int mp[mxn][mxn];
int n,m,T;
int main(){
n=read();m=read();T=read();
int i,j;
int u,v,d;
memset(mp,0x3f,sizeof mp);
for(i=;i<=m;i++){
u=read();v=read();d=read();
mp[u][v]=min(mp[u][v],d);
}
for(int k=;k<=n;++k)
for(i=;i<=n;++i)
for(j=;j<=n;++j)
mp[i][j]=min(mp[i][j],max(mp[i][k],mp[k][j]));
while(T--){
u=read();v=read();
if(mp[u][v]==0x3f3f3f3f)printf("-1\n");
else printf("%d\n",mp[u][v]);
}
return ;
}
洛谷P2888 [USACO07NOV]牛栏Cow Hurdles的更多相关文章
- 洛谷 P2888 [USACO07NOV]牛栏Cow Hurdles
题目戳 题目描述 Farmer John wants the cows to prepare for the county jumping competition, so Bessie and the ...
- bzoj1641 / P2888 [USACO07NOV]牛栏Cow Hurdles
P2888 [USACO07NOV]牛栏Cow Hurdles Floyd $n<=300$?果断Floyd 给出核心式,自行体会 $d[i][j]=min(d[i][j],max(d[i][k ...
- Luogu P2888 [USACO07NOV]牛栏Cow Hurdles
题目描述 Farmer John wants the cows to prepare for the county jumping competition, so Bessie and the gan ...
- [USACO07NOV]牛栏Cow Hurdles
OJ题号:洛谷2888 思路:修改Floyd,把边权和改为边权最大值.另外注意是有向图. #include<cstdio> #include<algorithm> using ...
- 洛谷P2886 [USACO07NOV]牛继电器Cow Relays
题意很简单,给一张图,把基本的求起点到终点最短路改成求经过k条边的最短路. 求最短路常用的算法是dijkstra,SPFA,还有floyd. 考虑floyd的过程: c[i][j]=min(c[i][ ...
- 洛谷 P2886 [USACO07NOV]牛继电器Cow Relays
题面 解题思路 ## floyd+矩阵快速幂,跟GhostCai爷打赌用不用离散化,最后完败..GhostCai真是tql ! 有个巧妙的方法就是将节点重新编号,因为与节点无关. 代码 #includ ...
- 洛谷P2886 [USACO07NOV]Cow Relays G (矩阵乘法与路径问题)
本题就是求两点间只经过n条边的最短路径,定义广义的矩阵乘法,就是把普通的矩阵乘法从求和改成了取最小值,把内部相乘改成了相加. 代码包含三个内容:广义矩阵乘法,矩阵快速幂,离散化: 1 #include ...
- 洛谷 P2887 [USACO07NOV]防晒霜Sunscreen 解题报告
P2887 [USACO07NOV]防晒霜Sunscreen 题目描述 To avoid unsightly burns while tanning, each of the C (1 ≤ C ≤ 2 ...
- 洛谷P1472 奶牛家谱 Cow Pedigrees
P1472 奶牛家谱 Cow Pedigrees 102通过 193提交 题目提供者该用户不存在 标签USACO 难度普及+/提高 提交 讨论 题解 最新讨论 暂时没有讨论 题目描述 农民约翰准备 ...
随机推荐
- Xcode7 使用AFNetWorking 报错 添加Security.framework
Undefined symbols for architecture x86_64: "_SecCertificateCopyData", referenced from: _AF ...
- 使用 Suricata 进行入侵监控(一个简单小例子访问百度)
前期博客 基于CentOS6.5下Suricata(一款高性能的网络IDS.IPS和网络安全监控引擎)的搭建(图文详解)(博主推荐) 1.自己编写一条规则,规则书写参考snort规则(suricata ...
- MS SqlServer 通过数据库日志文件找回已删除的记录
1.建立演示数据(创建数据库数据表添加基础数据) 1.1 创建数据库 1.2 创建数据表 1.3填充数据 1.4做数据库完整备份 2.模拟误删除.记录操作时间.备份数据库日志 2.1删除数据并记录操作 ...
- Kickstart Round D 2017 : A
思路: 动态规划. large数据的时间范围很大,无法设计入状态中.转换思路为定义dp[i][j]为当前在景点i,并且已经游览了j个景点所花费的最小时间,这种思想与leetcode45类似.于是转移方 ...
- 6 Specialzed layers 特殊层 第一部分 读书笔记
6 Specialzed layers 特殊层 第一部分 读书笔记 Specialization is a feature of every complex organization. 专注是 ...
- JSP标签 <meta.....>作用总结
<metahttp-equiv="pragma" content="no-cache"> <metahttp-equiv="cach ...
- redis-cli 工具--raw参数的作用
最近阅读了以redis官网关于--raw参数的解释,其功能有两个: 1.按数据原有格式打印数据,不展示额外的类型信息 例如:使用命令发送方式(redis在使用时有命令发送方式和交互方式两种)创建一个k ...
- Linux关于文件的权限笔记
1.调整文件的权限命令:chmodLinux的每个文件都定义了文件的拥有者:u(user).拥有组:g(group).其他人:o(others)权限,对应的权限用rwx的组合来定义.使用chmod命令 ...
- 【计算机网络】2.2 Web和HTTP
第二章第二节 Web和HTTP 这一章中,我们需要讨论5种重要的应用:Web.文件传输.电子邮件.目录服务.P2P:这一节中,我们将讨论Web和它的应用层协议HTTP. Outline Web简介 H ...
- gifsicle for linux ----------gif 图像处理
1.gifsicle 在linux 中的使用下载gifsicle yum install gifsicle 若发现没有此包 ,更新epel第三方软件库 sudo yum install epel-re ...