http://poj.org/problem?id=3615

floyd 最短路径的变形 dist[i][j]变化为 : i j之间的最大边

那么输入的时候可以直接把dist[i][j] 当作i j 之间的边进行输入

转移方程 dist[i][j] = max(dist[i][j], min(dist[i][k], dist[k][j]))

 #include <iostream>
#include <string.h>
#include <stdio.h>
#define INF 0x3fffffff
using namespace std;
const int maxn = ;
int Map[maxn][maxn]; int dist[maxn][maxn];//dist[i][j]表示 i 到 j 的最大边是多少?
//转移方程 dist[i][j] = min( dist[i][j] ,max(dist[i][k], dist[k][j])) ---> "**"
//
//与floyd的区别 dist是 i-j的最短'距离'
int main()
{
int m, n, k;
scanf("%d%d%d", &m, &n, &k);
for(int i = ; i <= m; i++)
for (int j = ; j <= m; j++)
dist[i][j] = INF;
for (int i = ; i < n; i++)
{
int from, to, cost;
scanf("%d%d%d", &from, &to, &cost);
dist[from][to] = cost;
}
for(int i = ; i <= m; i++)
{
for (int j = ; j <= m; j++)
{
for (int k = ; k <= m; k++)
{
// if (dist[j][k] == -1) dist[j][k] = max(dist[j][i], dist[i][k]);
//else
dist[j][k] = min(dist[j][k], max(dist[j][i], dist[i][k]));
}
}
}
for (int i = ; i < k; i++)
{
int from, to;
scanf("%d%d", &from, &to);
if (dist[from][to] == INF) cout << - << endl;
else cout << dist[from][to] << endl;
}
return ;
}

POJ 3615 Cow Hurdles的更多相关文章

  1. POJ 3615 Cow Hurdles(最短路径flyod)

    Cow Hurdles Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9337   Accepted: 4058 Descr ...

  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 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 ...

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

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

  8. POJ 3176 Cow Bowling(dp)

    POJ 3176 Cow Bowling 题目简化即为从一个三角形数列的顶端沿对角线走到底端,所取得的和最大值 7 * 3 8 * 8 1 0 * 2 7 4 4 * 4 5 2 6 5 该走法即为最 ...

  9. POJ 2184 Cow Exhibition【01背包+负数(经典)】

    POJ-2184 [题意]: 有n头牛,每头牛有自己的聪明值和幽默值,选出几头牛使得选出牛的聪明值总和大于0.幽默值总和大于0,求聪明值和幽默值总和相加最大为多少. [分析]:变种的01背包,可以把幽 ...

随机推荐

  1. go获取当前执行的位置程序

    func getCurrentPath() string { _, filename, _, ok := runtime.Caller(1) var cwdPath string if ok { cw ...

  2. spring事务问题

    springmvc中在service层中有如下逻辑:1.提交事务2.开启新线程,新线程中的业务依赖1中提交的事务处理办法:在service中新建一个方法do,调本地提交事务的方法doTranction ...

  3. function calling convention

    这是2013年写的一篇旧文,放在gegahost.net上面 http://raison.gegahost.net/?p=31 February 19, 2013 function calling c ...

  4. Devops 技术图谱

  5. js 跨域深入理解与解决方法

    参考博客: https://www.cnblogs.com/2050/p/3191744.html

  6. 【搜索】P1468 派对灯 Party Lamps

    P1468 派对灯 Party Lamps 我们来分析一下对灯的操作 1.对所有灯的,这时吧所有灯看成一个整体 2.奇偶数的操作,这时可以把每两个数看成一个循环节 3.对3X+ 1的操作,这时可以把每 ...

  7. PHP11 日期和时间

    学习要点 UNIX时间戳 将其他格式的日期转成UNIX时间戳格式 基于UNIX时间戳的日期计算 获取并格式化输出日期 修改PHP的默认时间 微秒的使用    Unix时间戳 相关概念 Unix tim ...

  8. [LOJ] 分块九题 2

    https://loj.ac/problem/6278 区间修改,查询区间第k大. 块内有序(另存),块内二分. 还是用vector吧,数组拷贝排序,下标搞不来.. //Stay foolish,st ...

  9. 25. TABLESPACES , 26. TABLE_CONSTRAINTS , 27. TABLE_PRIVILEGES

    25. TABLESPACES TABLESPACES表提供有关活动MySQL Cluster表空间的信息. TABLESPACES表有以下列: TABLESPACE_NAME :表空间名称 ENGI ...

  10. scp免密码拷贝和ssh免密码登录

    版权声明:本文为博主原创文章,未经允许不得转载. 在平常的工作中经常在两个服务器之间传输文件,而且经常从本地远程登录服务器,每次都要输入密码显然很没效率,这时候该怎么办呢? 首先假设服务器A和B,要想 ...