POJ 3615 Cow Hurdles(最短路径flyod)
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: 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 题意:
第一行输入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)的更多相关文章
- POJ 3615 Cow Hurdles
http://poj.org/problem?id=3615 floyd 最短路径的变形 dist[i][j]变化为 : i j之间的最大边 那么输入的时候可以直接把dist[i][j] 当作i j ...
- POJ 3045 Cow Acrobats (贪心)
POJ 3045 Cow Acrobats 这是个贪心的题目,和网上的很多题解略有不同,我的贪心是从最下层开始,每次找到能使该层的牛的风险最小的方案, 记录风险值,上移一层,继续贪心. 最后从遍历每一 ...
- 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 3348 Cow 凸包面积
Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8122 Accepted: 3674 Description ...
- POJ 1847 Tram (最短路径)
POJ 1847 Tram (最短路径) Description Tram network in Zagreb consists of a number of intersections and ra ...
- 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 ...
- POJ 3259 Wormholes(最短路径,求负环)
POJ 3259 Wormholes(最短路径,求负环) Description While exploring his many farms, Farmer John has discovered ...
- bzoj1641 / P2888 [USACO07NOV]牛栏Cow Hurdles
P2888 [USACO07NOV]牛栏Cow Hurdles Floyd $n<=300$?果断Floyd 给出核心式,自行体会 $d[i][j]=min(d[i][j],max(d[i][k ...
随机推荐
- request-html
目录 基本使用 获取链接( links 与 absolute_links ) CSS 选择器与 XPATH 支持 JavaScript 自定义 User-Agent 模拟表单提交(POST) asyn ...
- 嵊州普及Day4T1
题意:从n个数中选出k个数,使他们任意两数之差都等于m. 思路:任意差值都等于m,不就等价于k个数模m余数相同吗? 然后桶排储蓄一下各数余数即可. 见代码: #include<iostream& ...
- Nginx反向代理实现负载均衡配置图解
Nginx反向代理实现负载均衡配置图解 [导读] 负载均衡配置是超大型机器需要考虑的一些问题,同时也是数据安全的一种做法,下面我来介绍在nginx中反向代理 负载均衡配置图解,大家可参考本文章来操作. ...
- GET乱码以及POST乱码的解决方法
GET乱码以及POST乱码的解决方法 作者:东坡下载 来源:uzzf 发布时间:2010-10-14 11:40:01 点击: 一.GET乱码的解决方法 在tomcat的server.xml文件 ...
- 物联网学习笔记——构建RESTFul平台1
0.前言 前些时间顺着Yeelink学习了RESTFUL,使用PHP和Slim框架尝试实现简单的REST API,树莓派可通过GET方法获得JSON数据包,通过这种方式实现了树莓派和服务器(我 ...
- Hive事务原理和Datax同步事务表问题解决
一.事务的概述 1.定义 事务就是一组单元化操作,这些操作要么都执行,要么都不执行,是一个不可分割的工作单位. 2.特点 事务(transaction)具有的四个要素:原子性(Atomicity).一 ...
- 本地连接 HDFS 报错 Exception in thread "main" org.apache.hadoop.security.AccessControlException: org.apache.hadoop.security.AccessControlException: Permission denied: user=JM.H,access=WRITE, inode="":r
此时 到hdfs机器下修改hdfs-site.xml即可 添加如下配置 <property> <name>dfs.permissions</name> <va ...
- NFS PersistentVolume【转】
上一节我们介绍了 PV 和 PVC,本节通过 NFS 实践. 作为准备工作,我们已经在 k8s-master 节点上搭建了一个 NFS 服务器,目录为 /nfsdata: 下面创建一个 PV mypv ...
- iOS大V博客
王巍的博客:王巍目前在日本横滨任职于LINE.工作内容主要进行Unity3D开发,8小时之外经常进行iOS/Mac开发.他的陈列柜中已有多款应用,其中番茄工作法工具非常棒. http://onevca ...
- 用 Python 编写一个天气查询应用
效果预览: 一.获取天气信息 使用python获取天气有两种方式. 1)是通过爬虫的方式获取天气预报网站的HTML页面,然后使用xpath或者bs4解析HTML界面的内容. 2)另一种方式是根据天气预 ...