Heavy Cargo
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 4004   Accepted: 2124

Description

Big Johnsson Trucks Inc. is a company specialized in manufacturing big trucks. Their latest model, the Godzilla V12, is so big that the amount of cargo you can transport with it is never limited by the truck itself. It is only limited by the weight restrictions
that apply for the roads along the path you want to drive.

Given start and destination city, your job is to determine the maximum load of the Godzilla V12 so that there still exists a path between the two specified cities. 

Input

The input will contain one or more test cases. The first line of each test case will contain two integers: the number of cities n (2<=n<=200) and the number of road segments r (1<=r<=19900) making up the street network. 
Then r lines will follow, each one describing one road segment by naming the two cities connected by the segment and giving the weight limit for trucks that use this segment. Names are not longer than 30 characters and do not contain white-space characters.
Weight limits are integers in the range 0 - 10000. Roads can always be travelled in both directions. 
The last line of the test case contains two city names: start and destination. 
Input will be terminated by two values of 0 for n and r.

Output

For each test case, print three lines:

  • a line saying "Scenario #x" where x is the number of the test case
  • a line saying "y tons" where y is the maximum possible load
  • a blank line

Sample Input

4 3
Karlsruhe Stuttgart 100
Stuttgart Ulm 80
Ulm Muenchen 120
Karlsruhe Muenchen
5 5
Karlsruhe Stuttgart 100
Stuttgart Ulm 80
Ulm Muenchen 120
Karlsruhe Hamburg 220
Hamburg Muenchen 170
Muenchen Karlsruhe
0 0

Sample Output

Scenario #1
80 tons Scenario #2
170 tons

Source

Floyd直接解,唯一的难点是城市名称与图上点的对应,但是有STL还怕什么呢?

用STL的map保存城市和点的映射以后跑一遍floyd就行

 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<map>
#include<cstring>
using namespace std;
map<string,int>mp;
int m[][];
int n,r;
int cnt=;
int anscnt=;
void floyd(){
int i,j,k;
for(i=;i<=n;i++)
for(j=;j<=n;j++)
for(k=;k<=n;k++){
m[i][j]=max(m[i][j],min(m[i][k],m[k][j]));
}
return;
}
int main(){
while(scanf("%d%d",&n,&r)!=EOF && n!= &&r!=){
memset(m,,sizeof(m));
mp.clear();
cnt=;
int i,j;
for(i=;i<=n;i++)m[i][i]=;
//初始化
string u,v;//为了用STL的map,开了string
int x;
for(i=;i<=r;i++){
cin>>u>>v>>x;
if(!mp.count(u))mp[u]=++cnt;//城市名与结点对应
if(!mp.count(v))mp[v]=++cnt;
// cout<<u<<" "<<v<<" "<<cnt<<" "<<x<<endl;//测试
m[mp[u]][mp[v]]=m[mp[v]][mp[u]]=x;
}
floyd();
cin>>u>>v;
printf("Scenario #%d\n",++anscnt);
printf("%d tons\n\n",m[mp[u]][mp[v]]);
}
return ;
}

POJ2263 Heavy Cargo的更多相关文章

  1. POJ 2263 Heavy Cargo(Floyd + map)

    Heavy Cargo Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3768   Accepted: 2013 Descr ...

  2. poj2263 zoj1952 Heavy Cargo(floyd||spfa)

    这道题数据范围小,方法比较多.我用floyd和spfa分别写了一下,spfa明显有时间优势. 一个小技巧在于:把城市名称对应到数字序号,处理是用数字. 方法一:spfa #include<ios ...

  3. K - Heavy Cargo dijkstar

    来源poj2263 Big Johnsson Trucks Inc. is a company specialized in manufacturing big trucks. Their lates ...

  4. POJ-2263 Heavy Cargo---最短路变形&&最小边的最大值

    题目链接: https://vjudge.net/problem/POJ-2263 题目大意: 有n个城市,m条连接两个城市的道路,每条道路有自己的最大复载量.现在问从城市a到城市b,车上的最大载重能 ...

  5. Heavy Cargo POJ 2263 (Floyd传递闭包)

    Description Big Johnsson Trucks Inc. is a company specialized in manufacturing big trucks. Their lat ...

  6. POJ 2263 Heavy Cargo 多种解法

    好题.这题可以有三种解法:1.Dijkstra   2.优先队列   3.并查集 我这里是优先队列的实现,以后有时间再用另两种方法做做..方法就是每次都选当前节点所连的权值最大的边,然后BFS搜索. ...

  7. POJ 2263 Heavy Cargo(ZOJ 1952)

    最短路变形或最大生成树变形. 问 目标两地之间能通过的小重量. 用最短路把初始赋为INF.其它为0.然后找 dis[v]=min(dis[u], d); 生成树就是把最大生成树找出来.直到出发和终点能 ...

  8. 杭电ACM分类

    杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...

  9. HOJ题目分类

    各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...

随机推荐

  1. java14-4 Pattern和Matcher类的使用

     获取功能  Pattern和Matcher类的使用  模式和匹配器的基本使用顺序 import java.util.regex.Matcher; import java.util.regex.Pat ...

  2. ArcGIS Engine 中 线加箭头

            ;             ICartographicLineSymbol pCartoLineSymbol = );             IArrowMarkerSymbol p ...

  3. 1140 Jam的计数法

    1140 Jam的计数法 2006年NOIP全国联赛普及组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解  查看运行结果     题目描述 Descri ...

  4. C语言 原码--反码--补码

    //原码,反码,补码 #include<stdio.h> #include<stdlib.h> //数值的表示方法——原码.反码和补码 //原码:最高位为符号位,其余各位为数值 ...

  5. U3D rootMotion

    Body Transform The Body Transform is the mass center of the character. It is used in Mecanim's retar ...

  6. 构建基于WCF Restful Service的服务

    前言 传统的Asmx服务,由于遵循SOAP协议,所以返回内容以xml方式组织.并且客户端需要添加服务端引用才能使用(虽然看到网络上已经提供了这方面的Dynamic Proxy,但是没有这种方式简便), ...

  7. 职业卖家淘宝美工教程,掌握技能无师自通 学到的不只是PS(共81节)附素材【无水印版】

    职业卖家淘宝美工教程,掌握技能无师自通 学到的不只是PS(共81节)附素材[无水印版]设计传说出品的专业课程是我们资深培训讲师精心录制的,只有视频教程和常用必备的插件,其他绝不掺和,如果你是职业卖家, ...

  8. Android 动画之AlphaAnimation应用详解

    窗口的动画效果,淡入淡出什么的,有些游戏的欢迎动画,logo的淡入淡出效果就使用AlphaAnimation.AlphaAnimation(0.01f, 1.0f); 从0.01f到1.0f渐变.学过 ...

  9. [CareerCup] 9.6 Generate Parentheses 生成括号

    9.6 Implement an algorithm to print all valid (e.g., properly opened and closed) combinations of n-p ...

  10. Arduino智能小车制作报告

    Arduino智能小车制作报告 制作成员:20135224陈实  20135208贺邦  20135207王国伊 前提: Arduino,是一个开源的单板机控制器,采用了基于开放源代码的软硬件平台,构 ...