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 Centos 使用 yum 安装java
centos 使用 yum 安装java 首先,在你的服务器上运行一下更新. yum update 然后,在您的系统上搜索,任何版本的已安装的JDK组件. rpm -qa | grep -E '^op ...
- Dubbo(一) 开始认识Dubbo,分布式服务框架
引言: 以前的车马很慢,一生只够爱一个人以前的网站人很少,一个单应用服务着一个人--------------------现在,动不动就谈什么高并发,千万级访问.单应用?BOOM!分分钟爆炸.于是,技术 ...
- K:线性表
1. 线性表在计算机中可以用顺序存储和链式存储两种存储结构来表示.其中用顺序存储结构表示的线性表成为顺序表,用链式存储结构表示的线性表称为链表,链表又有单链表,双向链表,循环链表之分. 2. 线性表是 ...
- spring的基本使用
Spring的基本使用ioc,今天主要给大家说明了解决强耦合的联系,并且,注入的基本使用 Java里面的强耦合并且讲了spring是如何解决强耦合的第一种方式使用工厂模式,用的是反射,第二种方式是sp ...
- VS2010 Extension实践(2)
在上一篇(VS2010 Extension (1)实践)里,主要展示了如何使用MEF扩展VS2010,来扩展编辑控制和展现自己的UI:在实现QuickToolbar的时候,发现MEF仅仅提供了很基本的 ...
- Java的静态代码块是否会在类被加载时自动执行?
JAVA静态代码块会在类被加载时自动执行? 一.先看Java静态方法,静态变量 http://www.cnblogs.com/winterfells/p/7906078.html 静态代码块 在类中, ...
- Python day 6(5) Python 函数式编程3
一:装饰器 1 函数对象有一个__name__属性,可以拿到函数的名字 >>> def now(): ... print('2015-3-25') ... >>> ...
- hadoop集群篇--从0到1搭建hadoop集群
一.前述 本来有套好好的集群,可是不知道为什么虚拟机镜像文件损坏,结果导致集群不能用.所以不得不重新搭套集群,借此机会顺便再重新搭套吧,顺便提醒一句大家,自己虚拟机的集群一定要及时做好快照,最好装完每 ...
- windows编程学习笔记(三)ListBox的使用方法
ListBox是Windows中的一种控件,一般被当做子窗口使用,Windows中所有子窗口都是通过发送一个通知码到父窗口父窗口通过WM_COMMAND消息接收,并在此消息中处理,并控制子窗口,Lis ...
- office漏洞利用--获取shell
环境: kali系统, windows系统 流程: 在kali系统生成利用文件, kali系统下监听本地端口, windows系统打开doc文件,即可中招 第一种利用方式, 适合测试用: 从git下载 ...