POJ-3615_Cow Hurdles
Cow Hurdles
Time Limit: 1000MS Memory Limit: 65536K
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
题意:给与点和边,然后询问任意两点间的距离。若无法到达则输出-1
题解:用最暴力的Floyed算法求出所有点的最短路,然后根据询问输出就可以了。
#include <queue>
#include <cmath>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 255;
const int INF = 1e9 + 7;
int s[maxn][maxn];
int main()
{
int m,n,i,j,k,t,a,b,c;
scanf("%d%d%d",&n,&m,&t);
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
s[i][j] = i==j?0:INF;
for(i=0;i<m;i++)
{
scanf("%d%d%d",&a,&b,&c);
if(s[a][b]>c)
s[a][b] = c;
}
for(k=1;k<=n;k++)
{
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(max(s[i][k],s[k][j])<s[i][j])
s[i][j] = max(s[i][k],s[k][j]);
}
while(t--)
{
scanf("%d%d",&a,&b);
if(s[a][b]==INF)
printf("-1\n");
else
printf("%d\n",s[a][b]);
}
return 0;
}
POJ-3615_Cow Hurdles的更多相关文章
- POJ 3615 Cow Hurdles
http://poj.org/problem?id=3615 floyd 最短路径的变形 dist[i][j]变化为 : i j之间的最大边 那么输入的时候可以直接把dist[i][j] 当作i j ...
- POJ 3615 Cow Hurdles(最短路径flyod)
Cow Hurdles Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9337 Accepted: 4058 Descr ...
- 【转载】图论 500题——主要为hdu/poj/zoj
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...
- 图论常用算法之一 POJ图论题集【转载】
POJ图论分类[转] 一个很不错的图论分类,非常感谢原版的作者!!!在这里分享给大家,爱好图论的ACMer不寂寞了... (很抱歉没有找到此题集整理的原创作者,感谢知情的朋友给个原创链接) POJ:h ...
- POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理
Halloween treats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7644 Accepted: 2798 ...
- POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理
Find a multiple Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7192 Accepted: 3138 ...
- POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22286 ...
- POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法
Flip Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37427 Accepted: 16288 Descr ...
- POJ 3254. Corn Fields 状态压缩DP (入门级)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9806 Accepted: 5185 Descr ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
随机推荐
- 在VUE中实现打印
1.安装 npm install vue-print-nb --save 2.在mian.js中引入 import Print from 'vue-print-nb' Vue.use(Print); ...
- JavaScript中this的指向2(转载)
1. 每个函数都包含两个非继承而来的方法:call()方法和apply()方法. 2. 相同点:这两个方法的作用是一样的. 都是在特定的作用域中调用函数,等于设置函数体内this对象的值,以扩充函数赖 ...
- 读书笔记--iBATIS in Action 目录
1.iBATIS的理念 2.iBATIS是什么 3.安装和配置iBATIS 4.使用以映射语句 5.执行非查询语句 6.使用高级查询技术 7.事务 8.使用动态SQL 9.使用高速缓存提高性能 10. ...
- Jeecms网站直接访问html静态页面
jeecms网站维护,遇到了直接通过链接的方式访问静态页面,jeecms官网也做了详细的解答,但是没有得到满意的结果.但是通过自己的深入研究以及别人的帮助,发现了一个很好的解决方法. 首先说明一下je ...
- Eclipse-搭建springboot项目报错
Eclipse Maven pom报错: org.apache.maven.archiver.MavenArchiver.getManifest(org.apache.maven.project.Ma ...
- XML之基础和DTD解析
本笔记可根据W3school教程学习: 首先-----了解XML文档结构.语法规范.作用 -----了解DTD约束的作用.具体约束语法 <?xml version="1.0" ...
- 关于python的列表操作(二):排序,统计
# 列表操作 num_list = [2, 5, 8, 6, 7, 9, 5, 7] # 升序 num_list.sort() print(num_list) # 降序 num_list.sort(r ...
- day38 11-Spring的Bean的属性的注入:对象属性
package cn.itcast.spring3.demo5; public class Person { private String name;//人的名字 private Car2 car2; ...
- 2019-9-2-win10-uwp-存放网络图片到本地
title author date CreateTime categories win10 uwp 存放网络图片到本地 lindexi 2019-09-02 12:57:38 +0800 2018-2 ...
- 安装mysql报错2503
安装MySQL-5.5.27报这个错误: The installer has encountered an unexpected error installing this package.This ...