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. MySQL的重装问题解决方法

    最近在工作上遇到了在Windows环境中将MySQL重装的问题,今天记录一下我的解决过程. 首先因为某些原因,我不得不把mysql卸载,然后重装,不论我用控制面板的卸载删除程序方式还是安全卫士的卸载, ...

  2. ios之申请后台延时执行和做一个假后台的方法(系统进入长时间后台后,再进入前台部分功能不能实现)

    转自:http://sis hu ok.com/forum/blogCategory/showByCategory.html?categories_id=138&user_id=10385   ...

  3. 分享一个刷网页PV的python小脚本

    下面分享一个小脚本,用来刷网页PV. [root@huanqiu ~]# cat www.py #!/usr/bin/python# coding: UTF-8import webbrowser as ...

  4. TortoiseGIT安装过程及问题

    1,安装Git.一路默认 2,安装TortoiseGit,一路安装完毕.重启电脑. 3,配置TortoiseGit.这是最重要一步. 配置 remote,即远程地址,用于以后pull 或 push操作 ...

  5. Android开发探秘之一:创建可以点击的Button

    感觉到自己有必要学习下手机开发方面的知识,不论是为了以后的工作需求还是目前的公司项目. 当然,任何新东西的开始,必然伴随着第一个HelloWorld,Android学习也不例外.既然才开始,我就不做过 ...

  6. HTTP协议简介2

    几个相关的知识点: 客户端发送请求时,请求类型为GET与POST的主要差别是什么? 1.请求类型不同,一个为GET,一个为POST 2.当请求类型为GET时,请求的数据以参数的形式添加到url的后面, ...

  7. Linux常用指令---工作

    查看所有用户cat /etc/passwd 复制整个目录cp -ri A/B/* A1/B1/ 若复制过程中询问是否覆盖,输入y按回车 另外若A A1不在同一目录下,最好填绝对路径,就是/xxx/xx ...

  8. gcc学习

    gcc学习 预处理:gcc –E xxx.c –o xxx.i;产生预处理过的C原始程序 编 译:gcc –S xxx.i –o xxx.s;产生汇编语言原始程序 汇 编:gcc –c xxx.s – ...

  9. [译]Python编写虚拟解释器

    使用Python编写虚拟机解释器 一.实验说明 1. 环境登录 无需密码自动登录,系统用户名shiyanlou,密码shiyanlou 2. 环境介绍 本实验环境采用带桌面的Ubuntu Linux环 ...

  10. c#上利用NPlot实现动态曲线图需要的dll文件

    这儿暂时只提供我之间根据网上的方法编译出来的dll文件,大家如果需要直接在vs项目上导入就行了,然后在工具箱里就会自动添加一项,大家添加上去就知道了. 下载地址:http://pan.baidu.co ...