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. Hill密码

    希尔密码(Hill Password)是运用基本矩阵论原理的替换密码,由Lester S. Hill在1929年发明.每个字母当作26进制数字:A=, B=, C=... 一串字母当成n维向量,跟一个 ...

  2. 监控Mysql主从环境下Slave延迟状态的操作记录

    在MySQL主从环境下,通常会根据Seconds_Behind_Master的值来判断slave的延迟状态,这么做在大部分情况下尚可接受,但其实是并不够准确的.对于Slave延迟状态的监控,应该考虑多 ...

  3. zepto.js 源码解析

    http://www.runoob.com/w3cnote/zepto-js-source-analysis.html Zepto是一个轻量级的针对现代高级浏览器的JavaScript库, 它与jqu ...

  4. 利用concat进行数组复制

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. JS中的Navigator 对象

    Navigator 对象包含有关浏览器的信息. 很多时候我们需要在判断网页所处的浏览器和平台,Navigator为我们提供了便利 Navigator常见的对象属性如下: 属性 描述 appCodeNa ...

  6. 【转】【Asp.Net】asp.net服务器控件创建

    VS新建一个Web服务控件工程,会默认生成以下代码: namespace WebControlLibrary { [DefaultProperty("Text")] [Toolbo ...

  7. IBatis.Net学习笔记七--日志处理

    IBatis.Net中提供了方便的日志处理,可以输出sql语句等调试信息. 常用的有两种:1.输出到控制台:   <configSections>    <sectionGroup  ...

  8. [vim]vim 在win下乱码解决

    vim在win下遇到汉字乱码早就知晓,本以为通过如下设置即可解决乱码问题 set encoding=utf-8 set fileencoding=utf-8,chinese 这样设置是可以解决源码文件 ...

  9. 第一个WP8程序,照相机

    安装win8 64位,vs2013(包含wp8 sdk),百度各种得到学生开发者账户之后,终于可以试一下将自己的app部署到手机上的感觉了. 首先来个简单练练手的照相机功能 照相 即从主界面进入到照相 ...

  10. 20145208 《Java程序设计》第10周学习总结

    20145208 <Java程序设计>第10周学习总结 教材学习内容总结 了解JAVA网络编程的基础知识 这一部分知识的学习在我的实验中有叙述实验五 补充内容: 在现有的网络中,网络通讯的 ...