POJ2263 Heavy Cargo
来源:互联网 发布:映客辅助软件 编辑:程序博客网 时间:2024/06/11 08:01
Heavy Cargo
Time Limit: 1000MS Memory Limit: 65536KTotal 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.
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.
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 3Karlsruhe Stuttgart 100Stuttgart Ulm 80Ulm Muenchen 120Karlsruhe Muenchen5 5Karlsruhe Stuttgart 100Stuttgart Ulm 80Ulm Muenchen 120Karlsruhe Hamburg 220Hamburg Muenchen 170Muenchen Karlsruhe0 0
Sample Output
Scenario #180 tons Scenario #2170 tons
Source
Ulm Local 1998
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[200][200];int n,r;int cnt=0;int anscnt=0;void floyd(){int i,j,k;for(i=1;i<=n;i++) for(j=1;j<=n;j++) for(k=1;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!=0 &&r!=0){memset(m,0,sizeof(m));mp.clear();cnt=0;int i,j;for(i=1;i<=n;i++)m[i][i]=1000000;//初始化 string u,v;//为了用STL的map,开了string int x;for(i=1;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 0;}
0 0
- POJ2263:Heavy Cargo
- POJ2263 Heavy Cargo
- ZOJ1592 POJ2263 Heavy Cargo,Dijkstra算法
- poj2263 Heavy Cargo(dijstra 变形)
- poj2263 Heavy Cargo --- floyd求最大容量路
- POJ2263&ZOJ1952--Heavy Cargo【Floyd】多源最短路变形
- POJ2263 Heavy Cargo用最短路得到最大流
- poj2263&zoj1952Heavy Cargo(floyd)
- ZJU 1952 Heavy Cargo
- zoj 1952 Heavy Cargo
- POJ 2263 Heavy Cargo
- poj 2263 Heavy Cargo
- zoj 1952 Heavy Cargo
- poj_2263 Heavy Cargo (Dijkstra)
- poj 2263 Heavy Cargo
- 12:Heavy Cargo
- zoj Heavy Cargo
- POJ 2263 Heavy Cargo
- 深入浅出 消息队列 ActiveMQ
- Shader颜色渲染
- Python处理多个客户端连接---多路复用选择服务器
- 【Android】22、活动的启动模式——singleInstance
- 开发人员怎么做研究,深度好文
- POJ2263 Heavy Cargo
- 禁用cookie后session是如何传递(第2个)
- iOS开发-OC分支结构
- 禅道一键安装
- UIImage的扩展方法——裁剪图片和等比列缩放图片
- 课程练习三-1005-problem E
- Jetty(7.6.16)和VisualVM建立链接
- Android四大组件之Activity
- ubuntu16.04 jdk1.6.0_45配置