POJ2263 Heavy Cargo
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 4004 | Accepted: 2124 |
Description
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
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
- 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的更多相关文章
- POJ 2263 Heavy Cargo(Floyd + map)
Heavy Cargo Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3768 Accepted: 2013 Descr ...
- poj2263 zoj1952 Heavy Cargo(floyd||spfa)
这道题数据范围小,方法比较多.我用floyd和spfa分别写了一下,spfa明显有时间优势. 一个小技巧在于:把城市名称对应到数字序号,处理是用数字. 方法一:spfa #include<ios ...
- K - Heavy Cargo dijkstar
来源poj2263 Big Johnsson Trucks Inc. is a company specialized in manufacturing big trucks. Their lates ...
- POJ-2263 Heavy Cargo---最短路变形&&最小边的最大值
题目链接: https://vjudge.net/problem/POJ-2263 题目大意: 有n个城市,m条连接两个城市的道路,每条道路有自己的最大复载量.现在问从城市a到城市b,车上的最大载重能 ...
- Heavy Cargo POJ 2263 (Floyd传递闭包)
Description Big Johnsson Trucks Inc. is a company specialized in manufacturing big trucks. Their lat ...
- POJ 2263 Heavy Cargo 多种解法
好题.这题可以有三种解法:1.Dijkstra 2.优先队列 3.并查集 我这里是优先队列的实现,以后有时间再用另两种方法做做..方法就是每次都选当前节点所连的权值最大的边,然后BFS搜索. ...
- POJ 2263 Heavy Cargo(ZOJ 1952)
最短路变形或最大生成树变形. 问 目标两地之间能通过的小重量. 用最短路把初始赋为INF.其它为0.然后找 dis[v]=min(dis[u], d); 生成树就是把最大生成树找出来.直到出发和终点能 ...
- 杭电ACM分类
杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...
- HOJ题目分类
各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...
随机推荐
- JMeter学习(六)集合点
JMeter也有像LR中的集合点,本篇就来介绍下JMeter的集合点如何去实现. JMeter里面的集合点通过添加定时器来完成. 注意:集合点的位置一定要在Sample之前. 集合点:简单来理解一下, ...
- TestLink学习四:TestLink1.9.13使用说明
前言 测试管理工具,是指用工具对软件的整个测试输入.执行过程和测试结果进行管理的过程.可以提高回归测试的效率.大幅提升测试时间.测试质量.用例复用.需求覆盖等. TestLink用于进行测试过程中的管 ...
- js常用宽高属性
document.body.clientWidth //body对象的宽度 document.body.clientHeight //body对象的高度 document.documentElemen ...
- Sublime Text2 新建文件快速生成Html头部信息和炫酷的代码补全
预备:安装emmet插件(previously known as Zen Coding) 方法一 package control法: 上一篇博客已经介绍了如何安装package control.打开 ...
- 优化mysql主从下的slave延迟问题
一般而言,slave相对master延迟较大,其根本原因就是slave上的复制线程没办法真正做到并发.简单说,在master上是并发模式(以InnoDB引擎为主)完成事务提交的,而在slave上,复制 ...
- 微软职位内部推荐-SW Engineer for Skype
微软近期Open的职位: We are the Skype Beijing team. Skype division drives the communications strategy for Mi ...
- 制作苹果推送通知APNS服务器证书文件
1.准备证书申请文件 打开苹果电脑实用工具里的钥匙串访问程序 选择钥匙串访问—>证书助理—>从证书颁发机构申请证书 输入邮件地址,常用名词随便命名,在这里命名为APNS 选择存储到磁盘,将 ...
- [tools]camtasia studio8.6
实际情况: 装了汉化补丁包后坏事,最后还是没装汉化补丁包.直接用英文版的.安装过程中输入序列号即可激活. ):输入注册码安装 用户名:大眼仔~旭(Anan) 注册码:GCABC-CPCCE-BPMMB ...
- CentOS 7 添加win7启动项——修改默认启动项
CentOS 7使用grub2引导启动,在win7之后装完CentOS再启动会丢失win7启动项. 首先,添加win7启动项,步骤如下: 1.使用root登陆系统 2.用文本编辑器打开 /boot/g ...
- 对于JVM内存配置参数
-Xmx:最大堆大小 -Xms:初始堆大小 -Xmn:年轻代大小 -XXSurvivorRatio:年轻代中Eden区与Survivor区的大小比值 年轻代5120m, Eden:Survivor=3 ...