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.

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 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;}

 
 
原创粉丝点击