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 ...
随机推荐
- C和指针笔记 3.6链接属性
链接属性决定如何处理在不同文件中出现的标识符.标识符的作用域也它的链接属性有关,但这两个属性并不相同. 没有链接属性的标识符(none)总是被当作单独的个体,也就是说该标识符的多个声明被当作独立不同的 ...
- .Net 项目代码风格要求小结
代码风格没有正确与否,重要的是整齐划一,这是我拟的一份<.Net 项目代码风格要求>,供大家参考. 1. C# 代码风格要求1.1注释 类型.属性.事件.方法.方法参数,根据需要添加注释. ...
- Maven 其他功能
测试:指定测试哪些测试类,指定哪些测试类不测试,可以使用通配符 使用 Hudson 进行持续集成 持续集成:快速且高频率地自动构建项目的所有源码,并为项目成员提供丰富的反馈信息 一个典型的持续集成场景 ...
- 26Spring_的注解实际应用_关键整理一下之前的注解
写一个银行转账案例, 案例结构如下:
- Go 命令之 godep
本文参考:http://www.cnblogs.com/me115/p/5528463.html#h20 http://studygolang.com/articles/4385 关于Godep 发现 ...
- 【网站搭建教程】黑手VIP卡盟搭建教程(无KEY)
黑手VIP卡盟搭建教程(无KEY)教程介绍:第一课 卡盟介绍与课程流程.exe第七课 卡盟源码的搜集与选择_.exe第三课 卡盟域名之注册.exe第九课 IIS的本机架设_.exe第二课 卡盟域名之选 ...
- SQL语句的添加、删除、修改多种方法
SQL语句的添加.删除.修改虽然有如下很多种方法,但在使用过程中还是不够用,不知是否有高手把更多灵活的使用方法贡献出来? 添加.删除.修改使用db.Execute(Sql)命令执行操作╔------- ...
- python数字图像处理(14):高级滤波
本文提供更多更强大的滤波方法,这些方法放在filters.rank子模块内. 这些方法需要用户自己设定滤波器的形状和大小,因此需要导入morphology模块来设定. 1.autolevel 这个词在 ...
- 20135202闫佳歆--week 7 Linux内核如何装载和启动一个可执行程序--实验及总结
week 7 实验:Linux内核如何装载和启动一个可执行程序 1.环境搭建: rm menu -rf git clone https://github.com/megnning/menu.git c ...
- Jetty嵌入式Web容器攻略
Jetty是一个用 Java 实现.开源.基于标准的,并且具有丰富功能的 Http 服务器和 Web 容器.Jetty中应用最广泛的一项功能就是可以作为嵌入式Web容器. 在开发阶段,可以使用Jett ...