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. 【C#】枚举

    枚举 public static class CommonEnums { public enum people { /// <summary> ///男人 /// </summary ...

  2. IO 优化

    转自 BlackJack_ #define fastcall __attribute__((optimize("-O3"))) #define IL __inline__ __at ...

  3. [BZOJ1053][SDOI2005]反素数ant 数学

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1053 假设这个最大的反素数为$x$,那么$1<p<x$中数的因子数都没有$x$ ...

  4. [转]Qt 5.5 操作 Excel 的速度 效率问题

    转自:http://blog.csdn.net/li494816491/article/details/50274305 1. QAxObject *_excelObject1 =newQAxObje ...

  5. windows 下防火墙安全加固,配置规则

    netsh advfirewall firewall: 显示关于防火墙操作的常见命令的帮助信息 netsh advfirewall firewall show rule name=all dir=in ...

  6. Linux OpenGL 实践篇-11-shadow

    OpenGL 阴影 在三维场景中,为了使场景看起来更加的真实,通常需要为其添加阴影,OpenGL可以使用很多种技术实现阴影,其中有一种非常经典的实现是使用一种叫阴影贴图的实现,在本节中我们将使用阴影贴 ...

  7. fgetpos, fseek, fsetpos, ftell, rewind - 重定位某个流

    总览 (SYNOPSIS) #include <stdio.h> int fseek(FILE *stream, long offset, int whence); long ftell( ...

  8. example - 在这里插入一句话的简介

    总览 (SYNOPSIS) example [options] arguments 描述 (DESCRIPTION) 在这里插入描述 man9 应当是 “内核文档” 但是由于内核文档一般不以 man ...

  9. Codeforces Round #555 (Div. 3) 解题报告

    A.Reachable Numbers 题意: 给定操作f(x):将x加1,删去得到的数的所有末尾0,如f(10099)=10099+1=10100→1010→101.现在给定一个数n,对n进行无限次 ...

  10. linux 如何查看硬盘大小,内存大小等系统信息及硬件信息

    一.linux CPU大小[root@idc ~]# cat /proc/cpuinfo |grep "model name" && cat /proc/cpuin ...