您的位置:首页 > 编程语言 > Go语言

POJ-2263 Heavy Cargo

2014-08-15 16:06 302 查看
Heavy Cargo

Time Limit: 1000MS Memory Limit: 65536K
   
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 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

————————————————————集训15.4的分割线————————————————————
思路:只需要更新两点之间最大的最小值即可。水题不解释。
代码如下:
/*
ID: j.sure.1
PROG:
LANG: C++
*/
/****************************************/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <string>
#include <climits>
#include <iostream>
#define INF 0x3f3f3f3f
using namespace std;
/****************************************/
const int N = 205;
map <string, int> car;
int n, m, cnt, G

;

int MAP(string &s)
{
if(!car.count(s)) {
car[s] = cnt++;
}
return car[s];
}

void Floyd()
{
for(int k = 0; k < n; k++) {
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) if(k != i && k != j) {
G[i][j] = max(G[i][j], min(G[i][k], G[k][j]));
}
}
}
}

int main()
{
#ifdef J_Sure
freopen("000.in", "r", stdin);
// freopen(".out", "w", stdout);
#endif
string s1, s2;
int w, cas = 1;
while(scanf("%d%d", &n, &m)) {
if(!n && !m) break;
car.clear(); cnt = 0;
memset(G, 0, sizeof(G));
while(m--) {
cin >> s1 >> s2;
scanf("%d", &w);
int u = MAP(s1), v = MAP(s2);
G[u][v] = G[v][u] = w;
}
cin >> s1 >> s2;
int st = car[s1], ed = car[s2];
Floyd();
printf("Scenario #%d\n", cas++);
printf("%d tons\n\n", G[st][ed]);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: