BZOJ 1641 USACO 2007 Nov. Cow Hurdles 奶牛跨栏

【题解】
弗洛伊德。更新距离的时候把$f[i][j]=min(f[i][j],f[i][k]+f[k][j])$改为$f[i][j]=min(f[i][j],max(f[i][k],f[k][j]))$.
#include<cstdio>
#include<algorithm>
#include<cstring>
#define N (400)
#define rg register
using namespace std;
int n,m,t,a[N][N];
inline int read(){
int k=0,f=1; char c=getchar();
while(c<'0'||c>'9')c=='-'&&(f=-1),c=getchar();
while('0'<=c&&c<='9')k=k*10+c-'0',c=getchar();
return k*f;
}
int main(){
n=read(); m=read(); t=read();
for(rg int i=1;i<=n;i++)
for(rg int j=1;j<=n;j++) if(i!=j) a[i][j]=1e9;
for(rg int i=1,u,v;i<=m;i++) u=read(),v=read(),a[u][v]=read();
for(rg int k=1;k<=n;k++)
for(rg int i=1;i<=n;i++)
for(rg int j=1;j<=n;j++)
a[i][j]=min(a[i][j],max(a[i][k],a[k][j]));
for(rg int i=1;i<=t;i++){
int u=read(),v=read();
if(a[u][v]==1e9) puts("-1");
else printf("%d\n",a[u][v]);
}
return 0;
}
BZOJ 1641 USACO 2007 Nov. Cow Hurdles 奶牛跨栏的更多相关文章
- 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 ...
- 【BZOJ】1641: [Usaco2007 Nov]Cow Hurdles 奶牛跨栏(floyd)
http://www.lydsy.com/JudgeOnline/problem.php?id=1641 这种水题无意义... #include <cstdio> #include < ...
- BZOJ 1641: [Usaco2007 Nov]Cow Hurdles 奶牛跨栏
Description Farmer John 想让她的奶牛准备郡级跳跃比赛,贝茜和她的伙伴们正在练习跨栏.她们很累,所以她们想消耗最少的能量来跨栏. 显然,对于一头奶牛跳过几个矮栏是很容易的,但是高 ...
- BZOJ 1641 [Usaco2007 Nov]Cow Hurdles 奶牛跨栏:新版floyd【路径上最大边最小】
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1641 题意: 给你一个有向图,n个点(n <= 300),m条边,边权为h[i]. ...
- bzoj 1641: [Usaco2007 Nov]Cow Hurdles 奶牛跨栏【Floyd】
先跑一遍取max版的Floyd,直接用数组回答询问即可 #include<iostream> #include<cstdio> using namespace std; con ...
- bzoj1641 [Usaco2007 Nov]Cow Hurdles 奶牛跨栏
Description Farmer John 想让她的奶牛准备郡级跳跃比赛,贝茜和她的伙伴们正在练习跨栏.她们很累,所以她们想消耗最少的能量来跨栏. 显然,对于一头奶牛跳过几个矮栏是很容易的,但是高 ...
- BZOJ 1631 Usaco 2007 Feb. Cow Party
[题解] 最短路裸题.. 本题要求出每个点到终点走最短路来回的距离,因此我们先跑一遍最短路得出每个点到终点的最短距离,然后把边反向再跑一遍最短路,两次结果之和即是答案. #include<cst ...
- NC25025 [USACO 2007 Nov G]Sunscreen
NC25025 [USACO 2007 Nov G]Sunscreen 题目 题目描述 To avoid unsightly burns while tanning, each of the \(C\ ...
随机推荐
- 【Ubuntu】莫名其妙硬盘空间满了
一个个翻找,发现是 ~/.cache 占用了很多空间,遂删去其中内容 没有什么负面影响,删掉之后节省了许多空间
- 【Poj2960】S-Nim & 博弈论
Position: http://poj.org/problem?id=2960 List Poj2960 S-Nim List Description Knowledge Solution Noti ...
- 【POJ 1716】 Integer Intervals
[题目链接] 点击打开链接 [算法] 差分约束系统 [代码] #include <algorithm> #include <bitset> #include <cctyp ...
- 65. ExtJs获取文本框中值的几种方式
转自:https://blog.csdn.net/qiu512300471/article/details/17415675/ 1.Html文本框 如:<input type=" ...
- 数据库异常 :java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
最近在新项目中突然出现了 java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES) ...
- [Apple开发者帐户帮助]九、参考(5)支持的功能(tvOS)
tvOS应用程序可用的功能取决于您的程序成员身份. 能力 ADP 企业 Apple开发者 应用程序组 相关域名 背景模式 数据保护 游戏中心 游戏控制器 HomeKit iCloud:Cl ...
- Akka源码分析-ask模式
在我之前的博文中,已经介绍过要慎用Actor的ask.这里我们要分析一下ask的源码,看看它究竟是怎么实现的. 开发时,如果要使用ask方法,必须要引入akka.pattern._,这样才能使用ask ...
- ACM_Reverse Bits(反转二进制)
Reverse Bits Time Limit: 2000/1000ms (Java/Others) Problem Description: Reverse bits of a given 32 b ...
- 使用A*寻路小记
前几天做另一个DEMO 要用实现自动寻路功能,看到普遍都是A* 学习了下 我的主循环代码: isFindEndPoint = false; //主循环 do { CreateOutSkirtsNode ...
- [hihocoder][Offer收割]编程练习赛58
最大的K-偏差排列 每次取可选范围里的最大的数字,如果最左侧的数字还没有使用就直接使用最左侧的数字 #pragma comment(linker, "/STACK:102400000,102 ...