POJ 1797 Heavy Transportation(Dijkstra变形——最长路径最小权值)
题目链接:
http://poj.org/problem?id=1797
Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand business. But he needs a clever man who tells him whether there really is a way from the place his customer has build his giant steel crane to the place where it is needed on which all streets can carry the weight.
Fortunately he already has a plan of the city with all streets and bridges and all the allowed weights.Unfortunately he has no idea how to find the the maximum weight capacity in order to tell his customer how heavy the crane may become. But you surely know.
Problem
You are given the plan of the city, described by the streets (with weight limits) between the crossings, which are numbered from 1 to n. Your task is to find the maximum weight that can be transported from crossing 1 (Hugo's place) to crossing n (the customer's place). You may assume that there is at least one path. All streets can be travelled in both directions.
Input
Output
Sample Input
1
3 3
1 2 3
1 3 4
2 3 5
Sample Output
Scenario #1:
4
题意描述:
输入路口数及道路数以及每条路的承重量
计算并输出有最大承重量路径中的最小承重量(有点绕,其实就是最结实的那条路径中最不结实的一段路限重是多少)
解题思路:
最短路径问题的变型,处理数据使用迪杰斯特拉算法即可。
题目很经典,另外
最长路径最小权值题目 请参考博客:http://www.cnblogs.com/wenzhixin/p/7336948.html
最短路径双重最小权值题目参考博客:http://www.cnblogs.com/wenzhixin/p/7405802.html
代码实现:
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int inf=;
int d[],e[][],book[];
int main()
{
int t,n,m,i,j,t1,t2,t3,max,u,k,c=;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
for(i=;i<=n;i++)
for(j=;j<=n;j++)
e[i][j]=-inf;//初始化为无穷小值,后面求最长路径下的情况
for(i=;i<=m;i++)
{
scanf("%d%d%d",&t1,&t2,&t3);
e[t1][t2]=e[t2][t1]=t3;
}
for(i=;i<=n;i++)
d[i]=e[][i];
memset(book,,sizeof(book));
book[]=;
for(i=;i<=n-;i++)
{
max=-inf;
for(j=;j<=n;j++)//找到1到各个非树结点中(最小承重量)的最大承重量
{
if(!book[j] && d[j] > max)
{
max=d[j];
u=j;
}
}
book[u]=;
for(k=;k<=n;k++)
{//更新1到各个非树结点的最小承重量为
//之前的最大承重量 和 u到各个非树结点的承重量 中较小者 大于之前结果的承重量
if(!book[k] && d[k] < min(d[u],e[u][k]))//c++提交
d[k]=min(d[u],e[u][k]);
}
}
printf("Scenario #%d:\n%d\n\n",c++,d[n]);
//d中存的是从1到每个结点的最小承重量
}
return ;
}
POJ 1797 Heavy Transportation(Dijkstra变形——最长路径最小权值)的更多相关文章
- 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 (Dijkstra)
题目链接:POJ 1797 Description Background Hugo Heavy is happy. After the breakdown of the Cargolifter pro ...
- POJ 1797 Heavy Transportation / SCU 1819 Heavy Transportation (图论,最短路径)
POJ 1797 Heavy Transportation / SCU 1819 Heavy Transportation (图论,最短路径) Description Background Hugo ...
- poj 1797 Heavy Transportation(最大生成树)
poj 1797 Heavy Transportation Description Background Hugo Heavy is happy. After the breakdown of the ...
- 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 & ...
- Dijkstra(变形) POJ 1797 Heavy Transportation
题目传送门 题意:求1到n的最大载重量 分析:那么就是最大路上的最小的边权值,改变优先规则. #include <cstdio> #include <algorithm> #i ...
- poj 1797 Heavy Transportation(Dijkstar变形)
http://poj.org/problem?id=1797 给定n个点,及m条边的最大负载,求顶点1到顶点n的最大载重量. 用Dijkstra算法解之,只是需要把“最短路”的定义稍微改变一下, A到 ...
随机推荐
- Linux内置命令
主要Shell内置命令 Shell有很多内置在其源代码中的命令.这些命令是内置的,所以Shell不必到磁盘上搜索它们,执行速度因此加快.不同的Shell内置命令有所不同. A.2.1 bash内置命令 ...
- vue基础学习(一)
01-01 vue使用雏形 <div id="box"> {{msg}} </div> <script> window.onload= func ...
- rsync服务器的搭建
Rsync(remote synchronize)是一个远程数据同步工具,简要的概括就是主机于主机之间的文件目录数据的一个同步.下面就是rsync服务器的搭建过程. 系统环境 平台:Centos ...
- js选中文字兼容性解决
function selectText(){ if(document.selection){ //ie return document.selection.createRange().text; } ...
- Xamarin 简单的网络请求
//try //{ // var httpReq = (HttpWebRequest)HttpWebRequest.Create(new Uri(re ...
- Xamarin.android 重写axml控件
https://www.cnblogs.com/lonelyxmas/p/5632694.html <Laco: 用来用引指定的控件 android:layout_widt ...
- volatile关键字的特性总结
当一个变量定义为volatile后,它将具备两个特性: 1.保证此变量对所有线程的可见性,所谓"可见性",,是指当一个线程修改了这个变量的值,新值对于其他线程来说是可以立即得知的. ...
- [js高手之路] vue系列教程 - 绑定class与行间样式style(6)
一.绑定class属性的方式 1.通过数组的方式,为元素绑定多个class <style> .red { color:red; /*color:#ff8800;*/ } .bg { bac ...
- Java 非线程安全的HashMap如何在多线程中使用
Java 非线程安全的HashMap如何在多线程中使用 HashMap 是非线程安全的.在多线程条件下,容易导致死循环,具体表现为CPU使用率100%.因此多线程环境下保证 HashMap 的线程安全 ...
- 【Tarjan】洛谷P3379 Tarjan求LCA
题目描述 如题,给定一棵有根多叉树,请求出指定两个点直接最近的公共祖先. 输入输出格式 输入格式: 第一行包含三个正整数N.M.S,分别表示树的结点个数.询问的个数和树根结点的序号. 接下来N-1行每 ...