Luogu 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.
Farmer John 想让她的奶牛准备郡级跳跃比赛,贝茜和她的伙伴们正在练习跨栏。她们很累,所以她们想消耗最少的能量来跨栏。 显然,对于一头奶牛跳过几个矮栏是很容易的,但是高栏却很难。于是,奶牛们总是关心路径上最高的栏的高度。 奶牛的训练场中有 N (1 ≤ N ≤ 300) 个站台,分别标记为1..N。所有站台之间有M (1 ≤ M ≤ 25,000)条单向路径,第i条路经是从站台Si开始,到站台Ei,其中最高的栏的高度为Hi (1 ≤ Hi ≤ 1,000,000)。无论如何跑,奶牛们都要跨栏。 奶牛们有 T (1 ≤ T ≤ 40,000) 个训练任务要完成。第 i 个任务包含两个数字 Ai 和 Bi (1 ≤ Ai ≤ N; 1 ≤ Bi ≤ N),表示奶牛必须从站台Ai跑到站台Bi,可以路过别的站台。奶牛们想找一条路径从站台Ai到站台Bi,使路径上最高的栏的高度最小。 你的任务就是写一个程序,计算出路径上最高的栏的高度的最小值。
输入输出格式
输入格式:
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
行 1: 两个整数 N, M, T
行 2..M+1: 行 i+1 包含三个整数 Si , Ei , Hi
行 M+2..M+T+1: 行 i+M+1 包含两个整数,表示任务i的起始站台和目标站台: Ai , 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.
行 1..T: 行 i 为一个整数,表示任务i路径上最高的栏的高度的最小值。如果无法到达,输出 -1。
输入输出样例
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 上面做微小修改。正常的最短路是 sp(s, e) = min{sp(s, k) + sp(k, e)},这里最短路的计算方式不是边权求和而是边权求最大值,所以改成sp(s, e) = min{max{sp(s, k), sp(k,e)}} 即可。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read()
{
ll ret=,ok=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')ok=-;
ch=getchar();
}
for(;ch>=''&&ch<='';ch=getchar())
ret=ret*+ch-'';
return ret*ok;
}
ll n,m,t;
ll s,h,e;
ll a,b;
ll sp[][];
const int INF=0x7fffffff;
int main()
{
n=read(),m=read(),t=read();
memset(sp,0x3f,sizeof(sp));
for(int i=;i<=m;i++)
{
cin>>s>>e>>h;
sp[s][e]=h;
}
for(int i=;i<=n;i++)
sp[i][i]=;
for(int k=;k<=n;k++)
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
{
sp[i][j]=min(sp[i][j],max(sp[i][k],sp[k][j]));
}
for(int i=;i<=t;i++)
{
cin>>a>>b;
if(sp[a][b]>=INF)
cout<<-<<endl;
else
cout<<sp[a][b]<<endl;
}
return ;
}
Luogu P2888 [USACO07NOV]牛栏Cow Hurdles的更多相关文章
- bzoj1641 / P2888 [USACO07NOV]牛栏Cow Hurdles
P2888 [USACO07NOV]牛栏Cow Hurdles Floyd $n<=300$?果断Floyd 给出核心式,自行体会 $d[i][j]=min(d[i][j],max(d[i][k ...
- 洛谷 P2888 [USACO07NOV]牛栏Cow Hurdles
题目戳 题目描述 Farmer John wants the cows to prepare for the county jumping competition, so Bessie and the ...
- 洛谷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 ...
- 【题解】Luogu P2889 [USACO07NOV]挤奶的时间Milking Time
Luogu P2889 [USACO07NOV]挤奶的时间Milking Time 题目描述 传送门Bessie is such a hard-working cow. In fact, she is ...
- BZOJ 1641: [Usaco2007 Nov]Cow Hurdles 奶牛跨栏( floyd )
直接floyd.. ---------------------------------------------------------------------------- #include<c ...
- 1641: [Usaco2007 Nov]Cow Hurdles 奶牛跨栏
1641: [Usaco2007 Nov]Cow Hurdles 奶牛跨栏 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 424 Solved: 272 ...
- POJ 3615 Cow Hurdles(最短路径flyod)
Cow Hurdles Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9337 Accepted: 4058 Descr ...
- [LUOGU] P2886 [USACO07NOV]牛继电器Cow Relays
https://www.luogu.org/problemnew/show/P2886 给定无向连通图,求经过k条边,s到t的最短路 Floyd形式的矩阵乘法,同样满足结合律,所以可以进行快速幂. 离 ...
随机推荐
- spark-shell 显示乱码
用spark shell 进入console环境 查看字符集 scala> System.getProperty("file.encoding") res5: String ...
- zabbix-proxy搭建
环境: 因为公司需要监控远程客户机,但server端无法主动连接agent端,客户端可以连接公司ip 公司有固定ip,可以开放某个端口给zabbixserver,客户机agent端可以主动通过外网连接 ...
- NOI2001 食物链
食物链 题目描述 动物王国中有三类动物 A,B,C,这三类动物的食物链构成了有趣的环形.A 吃 B,B 吃 C,C 吃 A. 现有 N 个动物,以 1 - N 编号.每个动物都是 A,B,C 中的一种 ...
- 填坑:在 SegmentFault 开发单页应用之图片引用的问题探索
前言 前段时间,SegmentFault 低调上线了 技术号 模块,方便用户对数据进行集中管理.在开发过程中,第一次引入了 MV* 框架. SF 的基本架构还是后端路由,这也使得页面频繁地整体请求,体 ...
- Java高并发的常见应对方案
Java高并发的常见应对方案 一.关于并发我们说的高并发是什么? 在互联网时代,高并发,通常是指,在某个时间点,有很多个访问同时到来. 高并发,通常关心的系统指标与业务指标? QPS:每秒钟查询量,广 ...
- Restful、Jersey和JAX-RS
一:MVC与SpringMVC MVC:是一种思想,是一种设计模式 SpringMVC:是一个框架,实现了MVC这种思想. 之前:写JSP页面,比较繁琐.eg:在页面显示用户列表,我们会在JSP页面 ...
- 大白话说Java反射:入门、使用、原理
文章首发于[博客园-陈树义],点击跳转到原文<大白话说Java反射:入门.进阶.原理> 反射之中包含了一个「反」字,所以想要解释反射就必须先从「正」开始解释. 一般情况下,我们使用某个类时 ...
- 使用hbase小结
背景 hbase中一张表的rowkey定义为时间戳+字符串 需求 根据时间戳和列簇中某列的值为"abc",导出一天内的数据到excel中. 使用FilterList FilterL ...
- JMS基础篇(二)
简介 异构集成是消息发挥作用的一个领域,大型公司内部可能会遇到很多的平台,Java,.net或者公司自己的平台等. 传送消息还应该支持异步机制,以提高系统整体的性能.异步传输一条消息意味着,发送者不必 ...
- HDU [1529] || POJ [P1275] Cashier Employment
经典的差分约束+二分答案. 本题的难点在于如何建图. 设x[i] 表示第i个小时可以开始工作的有多少个人. num[i] 表示第i个小时最少需雇佣多少人. s[i] 表示1...i小时实际开始工作的有 ...