poj 2263 Heavy Cargo
来源:互联网 发布:ubuntu下安装apt get 编辑:程序博客网 时间:2024/05/16 09:28
Heavy Cargo
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 2555 Accepted: 1405
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
题解: 求的是最短路径里的最大承载量~ 不同的是需要字符串转换下标~ 简单的floyd解题~
这道题改了两天 错误的原因是开始字符串转换下标(match)的时候没有1的输出~
代码:
#include<iostream>#include<cstring>#include<cstdio>#include<string.h>using namespace std;int cn;int map[500][500];const int maxn=999999;char city[500][500];int n;int match(char c[]){int i;for( i=1;i<=cn;i++) if(strcmp(city[i],c)==0) return i; strcpy(city[i-1],c); cn++; return i-1;}void floyd(){for(int k=1;k<=n;k++) for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(map[i][j]<min(map[k][j],map[i][k])) { map[i][j]=min(map[i][k],map[k][j]); }}int main(){int m;int a,b,c;char city1[100],city2[100],city3[100],city4[100];int t=0;while(cin>>n>>m){for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) map[i][j]=0;if(m==0&&n==0) break; cn=1; for(int i=1;i<=m;i++) { cin>>city1>>city2>>c;a=match(city1);b=match(city2);//cout<<a <<b;map[a][b]=map[b][a]=c; }floyd();cin>>city3>>city4;a=match(city3);b=match(city4);cout<<"Scenario #"<<++t<<endl; cout<<map[a][b]<<" tons"<<endl<<endl;}return 0;}
- POJ 2263 Heavy Cargo
- poj 2263 Heavy Cargo
- poj 2263 Heavy Cargo
- POJ 2263 Heavy Cargo
- poj 2263 Heavy Cargo
- POJ:2263 Heavy Cargo
- POJ-2263 Heavy Cargo
- POJ 2263 Heavy Cargo
- poj 2263 Heavy Cargo
- [floyd]POJ 2263 Heavy Cargo
- poj 2263 Heavy Cargo(floyd)
- POJ 2263 Heavy Cargo(图的遍历)
- POJ 2263 Heavy Cargo(Dijkstra算法)
- poj 2263 Heavy Cargo(最短路+floyd)
- POJ 2263 Heavy Cargo 最短路dijkstra
- POJ 2263 Heavy Cargo 多种解法
- POJ 2263 Heavy Cargo(Floyd变形)
- POJ 2263 Heavy Cargo(ZOJ 1952)
- ubuntu 安装svn
- C++ 回溯算法 (递归的使用)
- poj 3928 树状数组
- oracle 在本地查询远程数据库的方法,如何组合远程链接字符串
- 从磁盘读取文本文件内容,用逗号隔开,用ArrayList输出
- poj 2263 Heavy Cargo
- 斐波那契数列(兔子数列)
- android 打包失败
- Bag-of-words model in computer vision
- Android.util.Log
- JS全局变量VAR和THIS--在函数内部,加var是局部变量,不加是全局变量
- VC++2012编程演练数据结构《3》堆栈实现进制转换
- 如何在区域集群上部署 Oracle RAC 11.2.0.3
- layoutSubviews在以下情况下会被调用