Cow Hurdles

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 9337   Accepted: 4058

Description

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: NM, 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 题意:
第一行输入n,m,t三个整数。
n表示有n个点,m表示有m条路线,t表示有t个奶牛需要经过的路线
接下来m行描述m条路线,每行表示由x到y需要跨过的高度为h
最后t行表示有t个奶牛,每个奶牛需要从起点s到终点t,问这个奶牛在s -> t过程中需要经过的最低高度是多少
//POJ3615
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
#define INF 123456789
int a[][]; //最大高度的最小值矩阵 int main()
{
int n, m, t;
int x, y, h;
while (scanf("%d%d%d", &n, &m, &t) != EOF)
{
for (int i = ; i <= n; i++) //初始化
for (int j = ; j <= n; j++)
{
if(i==j)
a[i][j]=;
else
a[i][j]=INF;
}
for (int i = ; i <= m; i++)//读入高度差
{
scanf("%d%d%d", &x, &y, &h);
a[x][y] = min(a[x][y], h); //更新子问题高度差
} for (int k = ; k <= n; k++) //Floyd
for (int i = ; i <= n; i++)
for (int j = ; j <= n; j++)
{
a[i][j] = min(a[i][j], max(a[i][k], a[k][j]));//DP思想
}
for (int i = ; i <= t; i++)
{
scanf("%d%d", &x, &y);
if (a[x][y] == INF) //输出,如果还是INF,那就代表不可达,两者时之间没有路径满足要求
printf("-1\n");
else
printf("%d\n",a[x][y]);
}
}
return ;
}

POJ 3615 Cow Hurdles(最短路径flyod)的更多相关文章

  1. POJ 3615 Cow Hurdles

    http://poj.org/problem?id=3615 floyd 最短路径的变形 dist[i][j]变化为 : i j之间的最大边 那么输入的时候可以直接把dist[i][j] 当作i j ...

  2. POJ 3045 Cow Acrobats (贪心)

    POJ 3045 Cow Acrobats 这是个贪心的题目,和网上的很多题解略有不同,我的贪心是从最下层开始,每次找到能使该层的牛的风险最小的方案, 记录风险值,上移一层,继续贪心. 最后从遍历每一 ...

  3. BZOJ 1641: [Usaco2007 Nov]Cow Hurdles 奶牛跨栏( floyd )

    直接floyd.. ---------------------------------------------------------------------------- #include<c ...

  4. 1641: [Usaco2007 Nov]Cow Hurdles 奶牛跨栏

    1641: [Usaco2007 Nov]Cow Hurdles 奶牛跨栏 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 424  Solved: 272 ...

  5. poj 3348 Cow 凸包面积

    Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8122   Accepted: 3674 Description ...

  6. POJ 1847 Tram (最短路径)

    POJ 1847 Tram (最短路径) Description Tram network in Zagreb consists of a number of intersections and ra ...

  7. POJ 3660 Cow Contest / HUST 1037 Cow Contest / HRBUST 1018 Cow Contest(图论,传递闭包)

    POJ 3660 Cow Contest / HUST 1037 Cow Contest / HRBUST 1018 Cow Contest(图论,传递闭包) Description N (1 ≤ N ...

  8. POJ 3259 Wormholes(最短路径,求负环)

    POJ 3259 Wormholes(最短路径,求负环) Description While exploring his many farms, Farmer John has discovered ...

  9. bzoj1641 / P2888 [USACO07NOV]牛栏Cow Hurdles

    P2888 [USACO07NOV]牛栏Cow Hurdles Floyd $n<=300$?果断Floyd 给出核心式,自行体会 $d[i][j]=min(d[i][j],max(d[i][k ...

随机推荐

  1. 一探torch.nn究竟“What is torch.nn really?”

    来自: https://pytorch.org/tutorials/beginner/nn_tutorial.html <What is torch.nn really?>这文章看起来不能 ...

  2. Linux centosVMware su命令、sudo命令、限制root远程登录

    一.su命令 Linux系统中有些事情只有root用户才能做,普通用户不能做,这时候就需要临时切换到root身份了. [root@davery ~]# whoamiroot [root@davery ...

  3. 在Linux上安装Oracle服务的操作步骤

    如题,将我在云服务器上安装Oracle服务的惨痛经历分享出来,期间查找的资料踩过的坑无数,希望对大家能有帮助 闲话少叙,直接开始 首先,由于服务器比较差,需要先设置swap 查看是否设置swap虚拟内 ...

  4. Python—网络通信编程之udp通信编程

    服务端代码 import socket # 1.创建实例,即数据报套接字 server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # 2.绑 ...

  5. 01.DesignParttern设计模式,简单工厂,工厂方法,抽象工厂三大工厂的区别与联系

                工厂用来生产对象,对象具有方法和属性. 简单工厂的缺点(简单工厂并不是23中设计模式): 工厂类的职责相对过重,增加新的产品,需要修改工厂类的判断逻辑,违背开闭原则: JDK源 ...

  6. P1073 多选题常见计分法

    P1073 多选题常见计分法 转跳点:

  7. firewalld学习--service

    service是firewalld中另外一个非常重要的概念.还是拿门卫的例子来解释. 在iptables的时代我们给门卫下达规则时需要告诉他“所有到22号楼的人全部予以放行”.“所有到80号楼的人全部 ...

  8. 使用 Helm【转】

    Helm 安装成功后,可执行 helm search 查看当前可安装的 chart. 这个列表很长,这里只截取了一部分.大家不禁会问,这些 chart 都是从哪里来的? 前面说过,Helm 可以像 a ...

  9. GNS3 模拟免费ARP

    R2 : conf t int f0/0 no shutdown ip add 192.168.1.254 255.255.255.0 end R1 : conf t int f0/0 no shut ...

  10. vue-router 一个十分简单的应用场景

    时间:2018-03-28 关于vue-router: 这里只大致说一下构建过程和使用情况,将就看看!! 我使用的是vue-cli脚手架+webpack构建的项目 安装vue-cli脚手架 npm i ...