POJ1797 Heavy Transportation
来源:互联网 发布:php final类 编辑:程序博客网 时间:2024/06/05 07:47
Background
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.
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.
The first line contains the number of scenarios (city plans). For each city the number n of street crossings (1 <= n <= 1000) and number m of streets are given on the first line. The following m lines contain triples of integers specifying start and end crossing of the street and the maximum allowed weight, which is positive and not larger than 1000000. There will be at most one street between each pair of crossings.
The output for every scenario begins with a line containing "Scenario #i:", where i is the number of the scenario starting at 1. Then print a single line containing the maximum allowed weight that Hugo can transport to the customer. Terminate the output for the scenario with a blank line.
13 31 2 31 3 42 3 5
Scenario #1:4
有一个城市有若干的路,每条路有自身的最大承重限制,比如A-B-C,A-B承重2kg,B-C承重3kg故这条通路最大承重2kg
第一行是 计划个数
第二行 n m
n表示 从1要到n处去
m行数据 x处---y处 承受最大重量
数据<=10^6
同frogger ,找到1-n所有路径中的最小承载重量,在这些可行的最小承载重量中找到一条路,这条路的最小承载重量最大。
核心代码:
for(j=2;j<=n;j++)
{
length=min(weight[k],map[k][j]);
weight[j]=max(weight[j],length);
}
找到weight[k]是1-k最大承重质量,k可以到j,找到min(weight[k],map[k][j]),就是1-j的最大承重重量。
注意map数组要开的大几个数据,否则会越界。
#include<iostream> #include<cstring>#include<cstdio>#include<cmath>#include<algorithm>using namespace std;#define MAXN 1007#define INF 1<<30int plan_num,n,m;int weight[MAXN];int map[MAXN][MAXN];void input(){int i,j,x,y,w;for(i=1;i<=n;i++)for(j=1;j<=n;j++)map[i][j]=0;scanf("%d%d",&n,&m);i=m;while(i--){scanf("%d%d%d",&x,&y,&w);//cout<<x<<y<<w<<endl;map[x][y]=map[y][x]=w;}}void dijkstar(){int i,j,temp,k,length;bool flag[MAXN];memset(flag,false,sizeof(flag));for(i=1;i<=n;i++)weight[i]=map[1][i];for(i=1;i<=n;i++){temp=-INF;for(j=2;j<=n;j++){if(!flag[j]&&(temp<weight[j])){k=j;temp=weight[j];}}flag[k]=true;for(j=2;j<=n;j++){length=min(weight[k],map[k][j]);weight[j]=max(weight[j],length);/*if((!flag[j])&&(weight[j]<min(weight[k],map[k][j])))weight[j]=min(weight[k],map[k][j]);*/}/*for(j=1;j<=m;j++)cout<<weight[j]<<" ";cout<<endl;*/}}int main(){int i,j;scanf("%d",&plan_num);for(i=1;i<=plan_num;i++){input();dijkstar();printf("Scenario #%d:\n",i);printf("%d\n\n",weight[n]);} }
0 0
- Heavy Transportation (POJ1797)
- poj1797 - Heavy Transportation
- POJ1797--Heavy Transportation
- poj1797 Heavy Transportation
- POJ1797 Heavy Transportation 【Dijkstra】
- POJ1797 Heavy Transportation
- POJ1797 Heavy Transportation
- poj1797 Heavy Transportation
- [poj1797] Heavy Transportation
- POJ1797 Heavy Transportation
- POJ1797 Heavy Transportation
- POJ1797 Heavy Transportation
- POJ1797——Heavy Transportation
- 【POJ1797】Heavy Transportation 最短路
- poj1797 Heavy Transportation spfa变形
- 【POJ1797】Heavy Transportation【dijkstra优化】
- 【POJ1797】【Heavy Transportation】【dij变形】
- POJ1797 Heavy Transportation 最短路
- 可变参数列表 va_list
- Qt,QtCreator资源下载地址
- Linux学习篇第二章之~unit6 文本处理工具
- Seaborn 统计数据可视化图标库 Overview
- 如何解决Eureka Server不剔除已关停的节点的问题?
- POJ1797 Heavy Transportation
- android java进程管理(八)之lowmemorykiller
- 存储过程详解
- Noip201502统计质数
- MongoDB_Architecture_Guide(MongoDB架构指导个人翻译)
- mui中a标签跳转问题
- Binary Tree Tilt
- poj 1083 求n条线段覆盖的最大相交次数
- 【numpy入门】-- 安装及简介