UVA 544

UVA 544:

题目介绍:
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.

题目大意:
给了一系列在两个城市的最大承重,算起点到终点的最大可能载重。

分析:
类似最短路判断。首先对城市名做一个映射,然后直接使用dijastra算法即可。

#Ac代码:
下面展示一些 。

#include<iostream>
#include<map>
#include<cstring>
#include<climits>
using namespace std;

int len,road[205][205];

int main(){
	int n,k,Case=1;
	while(scanf("%d%d",&n,&k)==2&&n){
		len=0;
		memset(road,0,sizeof(road));
		map<string,int> now;
		for(int i=0;i<k;i++){
			string a,b;
			int c;
			cin>>a>>b>>c;
			int t1,t2;
			if(!now.count(a))now[a]=len++;
			if(!now.count(b))now[b]=len++;
			t1=now[a];
			t2=now[b];
			road[t1][t2]=road[t2][t1]=c;
		}
		string a,b;
		int bg,ed;
		cin>>a>>b;
		bg=now[a];
		ed=now[b];
		int vis[205]={0},ans[205]={0};
		for(int i=0;i<n;i++)
			ans[i]=road[bg][i];
		vis[bg]=1;
		while(1){
			int Max=0,k;
			for(int i=0;i<n;i++){
				if(!vis[i]&&ans[i]>Max){
					Max=ans[i];
					k=i;
				}
			}
			vis[k]=1;
			if(vis[ed])break;
			for(int i=0;i<n;i++){
				if(!vis[i]&&road[k][i]){
					ans[i]=max(ans[i],min(ans[k],road[k][i]));
				}
			}
		}
		printf("Scenario #%d\n",Case++);
		printf("%d tons\n\n",ans[ed]);
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值