poj 1797 Heavy Transportation(Dijkstar变形)
http://poj.org/problem?id=1797
给定n个点,及m条边的最大负载,求顶点1到顶点n的最大载重量。
用Dijkstra算法解之,只是需要把“最短路”的定义稍微改变一下,
A到B的路长定义为路径上边权最小的那条边的长度,
而最短路其实是A到B所有路长的最大值。
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<algorithm>
#define N 1010
#define INF 0x3f3f3f3f using namespace std; int G[N][N], dist[N];
bool vis[N];
int n; void Init()
{
int i;
memset(vis, false, sizeof(vis));
for(i = ; i <= n ; i++)
dist[i] = G[][i];//dist[i]表示从起点到i点的载重量
} int Dij(int Start, int End)
{
int Max, i, j, index;
dist[Start] = ;
for(i = ; i <= n ; i++)
{
Max = ;
for(j = ; j <= n; j++)
{
if(!vis[j] && Max < dist[j])
{
Max = dist[j];
index = j;
}
}//找最大载重量
vis[index] = true;
for(j = ; j <= n ; j++)
{
if(!vis[j] && dist[j] < min(dist[index], G[index][j]))
dist[j] = min(dist[index], G[index][j]);
}
}
return dist[End];
} int main()
{
int m, a, b, c, t, x = ;
scanf("%d", &t);
while(t--)
{
x++;
memset(G, , sizeof(G));
scanf("%d%d", &n, &m);
while(m--)
{
scanf("%d%d%d", &a, &b, &c);
G[a][b] = G[b][a] = c;
}
Init();
printf("Scenario #%d:\n%d\n\n", x, Dij(, n));
}
return ;
}
poj 1797 Heavy Transportation(Dijkstar变形)的更多相关文章
- POJ.1797 Heavy Transportation (Dijkstra变形)
POJ.1797 Heavy Transportation (Dijkstra变形) 题意分析 给出n个点,m条边的城市网络,其中 x y d 代表由x到y(或由y到x)的公路所能承受的最大重量为d, ...
- POJ 1797 Heavy Transportation SPFA变形
原题链接:http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K T ...
- poj 1797 Heavy Transportation(最大生成树)
poj 1797 Heavy Transportation Description Background Hugo Heavy is happy. After the breakdown of the ...
- POJ 1797 Heavy Transportation / SCU 1819 Heavy Transportation (图论,最短路径)
POJ 1797 Heavy Transportation / SCU 1819 Heavy Transportation (图论,最短路径) Description Background Hugo ...
- POJ 1797 Heavy Transportation
题目链接:http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K T ...
- POJ 1797 Heavy Transportation (Dijkstra变形)
F - Heavy Transportation Time Limit:3000MS Memory Limit:30000KB 64bit IO Format:%I64d & ...
- POJ 1797 Heavy Transportation(最大生成树/最短路变形)
传送门 Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 31882 Accept ...
- POJ 1797 ——Heavy Transportation——————【最短路、Dijkstra、最短边最大化】
Heavy Transportation Time Limit:3000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I64 ...
- poj 1797 Heavy Transportation(最短路径Dijkdtra)
Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 26968 Accepted: ...
- POJ 1797 Heavy Transportation (最大生成树)
题目链接:POJ 1797 Description Background Hugo Heavy is happy. After the breakdown of the Cargolifter pro ...
随机推荐
- (转载)DataTable使用技巧总结
在项目中经常用到DataTable,如果DataTable使用得当,不仅能使程序简洁实用,而且能够提高性能,达到事半功倍的效果,现对DataTable的使用技巧进行一下总结. 一.Da ...
- HDU 5348 MZL's endless loop 给边定向(欧拉回路,最大流)
题意: 给一个所有你可能想得到的奇葩无向图,要求给每条边定向,使得每个点的入度与出度之差不超过1.输出1表示定向往右,输出0表示定向往左. 思路: 网络流也是可以解决的!!应该挺简单理解的.但是由于复 ...
- LeetCode Valid Number 有效数字(有限自动机)
题意:判断一个字符串是否是一个合法的数字,包括正负浮点数和整形. 思路:有限自动机可以做,画个图再写程序就可以解决啦,只是实现起来代码的长短而已. 下面取巧来解决,分情况讨论: (1)整数 (2)浮点 ...
- Perfect smooth scrolling in UITableViews
https://medium.com/ios-os-x-development/perfect-smooth-scrolling-in-uitableviews-fd609d5275a5 Diffic ...
- scala学习笔记(8): 列表的map,flatMap,zip和reduce
map,flatMap,zip和reduce函数可以让我们更容易处理列表函数. 1 map函数map将一个函数应用于列表的每一个元素并且将其作为一个新的列表返回.我们可以这样对列表的元素进行平方: s ...
- LSTM网络(Long Short-Term Memory )
本文基于前两篇 1. 多层感知机及其BP算法(Multi-Layer Perceptron) 与 2. 递归神经网络(Recurrent Neural Networks,RNN) RNN 有一个致命的 ...
- yaf框架流程一
资料参考: Yaf是一个C语言编写的PHP框架,以php扩展的形式. 是 laruence(鸟哥) 的作品 laruence 是PHP 开发组成员, PECL 开发者. Yaf, Taint等Pec ...
- android动画学习
android动画学习 转载自:http://www.open-open.com/lib/view/open1329994048671.html 3.0以前,android支持两种动画模式,twe ...
- mysql 查看所有存储过程
转载地址:http://zhuixue.iteye.com/blog/375353 查询数据库中的存储过程 方法一: select `name` from mysql.proc where db = ...
- Linux/Unix shell sql 之间传递变量
灵活结合Linux/Unix Shell 与SQL 之间的变量传输,极大程度的提高了DBA的工作效率,本文针对Linux/Unix shell sql 之间传递变量给出几个简单的示例以供参考. Lin ...