POJ2263 Heavy Cargo
2012-08-18 15:16
211 查看
Heavy Cargo
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
Sample Output
Source
Ulm Local 1998
思路:给出N个地点,然后给出这些地点之间的路径可以承受的汽车最大的压力。首先将这N个地点映射为数字。然后建立矩阵。最后可以用求最短路径的方法进行变形,从而求出答案。
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 2412 | Accepted: 1321 |
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 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
Ulm Local 1998
思路:给出N个地点,然后给出这些地点之间的路径可以承受的汽车最大的压力。首先将这N个地点映射为数字。然后建立矩阵。最后可以用求最短路径的方法进行变形,从而求出答案。
#include <cstdlib> #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <map> #define MAXINT 99999999 using namespace std; int data[204][204]; int dis[204]; int isVis[204]; char maps[204][34]; int length=0; int findv(char str[34]) { int i; for(i=1;i<length;i++) { if(strcmp(maps[i],str)==0) return i; } strcpy(maps[length],str); length++; return length-1; } int minn(int x,int y) {if(x>y) return y; return x; } int main(int argc, char *argv[]) { int i,j,k; int n,m; int ncount=0; while(scanf("%d%d",&n,&m)!=EOF) { if((n==0)&&(m==0)) break; length=1; getchar(); ncount++; for(i=1;i<=n;i++) for(j=1;j<=n;j++) data[i][j]=0; for(i=1;i<=m;i++) { char s1[34],s2[34]; int w; scanf("%s%s%d",s1,s2,&w); getchar(); int v1=findv(s1); int v2=findv(s2); data[v1][v2]=data[v2][v1]=w; } char s1[34],s2[34]; scanf("%s%s",s1,s2); getchar(); int startv=findv(s1); int endv=findv(s2); for(i=1;i<=n;i++) isVis[i]=0; for(i=1;i<=n;i++) {dis[i]=data[startv][i];} int maxdis=0; isVis[startv]=1; for(i=1;i<=n;i++) { k=-1; maxdis=0; for(j=1;j<=n;j++) { if((isVis[j]==0)&&(maxdis<dis[j])) {k=j;maxdis=dis[j];} } isVis[k]=1; for(j=1;j<=n;j++) { int tmp=minn(dis[k],data[k][j]); if((isVis[j]==0)&&(dis[j]<tmp)) {dis[j]=tmp;} } } printf("Scenario #%d\n",ncount); printf("%d tons\n\n",dis[endv]); } //system("PAUSE"); return EXIT_SUCCESS; }
相关文章推荐
- ZOJ1592 POJ2263 Heavy Cargo,Dijkstra算法
- poj2263 Heavy Cargo --- floyd求最大容量路
- POJ2263:Heavy Cargo
- POJ2263 Heavy Cargo
- POJ2263 Heavy Cargo
- POJ2263 Heavy Cargo用最短路得到最大流
- ZOJ 1952 Heavy Cargo【SPFA】
- HOJ 1653 Heavy Transportation&& HOJ 1460 Heavy Cargo (Dijkstra 单源最短路)
- (beginer) 最小生成树 UVA 544 Heavy Cargo
- floyd UVA544 Heavy Cargo
- Heavy Cargo(uva 544)
- poj 2263 Heavy Cargo 求a到b路上最小值中的最大值
- POJ 2663 Heavy Cargo & ZOJ 1952 Heavy Cargo
- POJ 2263 Heavy Cargo 多种解法
- poj 2263 Heavy Cargo(floyd)
- POJ 2263 Heavy Cargo
- poj2263-没有在比赛中a掉的水题
- poj 2263 Heavy Cargo(floyd)
- POJ2263 dij应用
- poj 2263 Heavy Cargo