`
zsybupt
  • 浏览: 41568 次
  • 性别: Icon_minigender_1
社区版块
存档分类
最新评论

boj 12

    博客分类:
  • oj
 
阅读更多

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

 

大三的时候交了,一直CE,后来发现是自己变了命名的时候有个int count,可能与oj上的重复了,改成cnt后过了,就是用dijkstra,不过此时是寻找能承受最大重量的路径。

代码:

#include<iostream>
using namespace std;
int dp[300][300],weigh[300],flag[300],n,r,cnt;
char  f[300][35];
int find_num(char *a)
{
	bool flag_=0;
	int i;
	for(i=1;i<=cnt;i++)
	{
		if(strcmp(a,f[i])==0)
		{
			flag_=1;
			break;
		}
	}
	if(flag_==0)strcpy(f[++cnt],a);
	return i;
}
int main()
{
	int num=1;
	char start[20],endd[20];
	scanf("%d %d",&n,&r);
	while(!(n==0&&r==0))
	{
		memset(weigh,0,sizeof(weigh));
		memset(flag,0,sizeof(flag));
		memset(dp,0,sizeof(dp));
		int i;
		cnt=0;
		for(i=0;i<r;i++)
		{
			char x[20],y[20];
			int weight,xi,yi;
			scanf("%s %s %d",x,y,&weight);
			xi=find_num(x);
			yi=find_num(y);
			if(!dp[xi][yi])
				dp[xi][yi]=dp[yi][xi]=weight;
			else
				dp[xi][yi]=dp[yi][xi]=min(weight,dp[xi][yi]);
		}
		scanf("%s %s",start,endd);
		int sta=find_num(start);
		int end=find_num(endd);
		weigh[sta]=10003;
		for(i=0;i<n;i++)
		{
			int x,m=0;
			for(int y = 1;y <= n;y++)if(!flag[y] && weigh[y]>=m) m = weigh[x=y];
			flag[x]=1;
			for(int y = 1;y <=n;y++)
			{
				if(weigh[y]<min(weigh[x],dp[x][y]))
					weigh[y]=min(weigh[x],dp[x][y]);
			}
		}
		printf("Scenario #%d\n%d tons\n\n",num++,weigh[end]);
		scanf("%d %d",&n,&r);
	}
}

 

分享到:
评论

相关推荐

    BOJ题目1023. Ancient Keyboard 源代码

    BOJ的题目1023. Ancient Keyboard解法 源代码

    boj 0809复试模拟题答案

    boj 上08 09 年复试模拟题的答案

    boj:算法

    boj:算法

    JAVA_BOJ

    JAVA_BOJ

    Algorithm-BOJ.zip

    Algorithm-BOJ.zip,BekJon在线法官(Java,Kotlin,SWIFT)和PS路线图,算法是为计算机程序高效、彻底地完成任务而创建的一组详细的准则。

    BOJ

    BOJ

    Algorithm-BOJ-PSJ.zip

    Algorithm-BOJ-PSJ.zip,Baykon在线判断JAVA问题解决方法(第二章),算法是为计算机程序高效、彻底地完成任务而创建的一组详细的准则。

    Algorithm-BOJ-AutoCommit.zip

    Algorithm-BOJ-AutoCommit.zip,当您解决baekjoon online judge的问题时,它会自动提交并推送到远程存储库。,算法是为计算机程序高效、彻底地完成任务而创建的一组详细的准则。

    Algorithm-boj-auto-submit.zip

    Algorithm-boj-auto-submit.zip,日本央行cli提交脚本,算法是为计算机程序高效、彻底地完成任务而创建的一组详细的准则。

    Python库 | boj-0.0.1.tar.gz

    资源分类:Python库 所属语言:Python 资源全名:boj-0.0.1.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059

    Boj Coloring Book-crx插件

    通过这本图画书展示您的创造力,其中包括Boj和朋友。 一本有趣的,全数字化且可重复使用的着色书,可用于 通过这本图画书展示您的创造力,其中包括Boj和朋友。 一本有趣的全数字可重复使用的图画书,专为孩子,父母...

    boj.kr:解决boj.kr的问题

    解决问题 Boj.kr

    PS_BOJ:BOJ문제풀이

    欢迎来到PS_BOJ 이곳은... J이한BOJ문제들의AC코드들이입니다。 안내 :check_mark: C ++ Python으로풀이합니다。 :check_mark: ++ C ++풀이하며 long long 필요하거나으으으으으으으으으끔씩만끔씩만끔씩만끔씩만...

    BOJ:日本央行

    BOJ:日本央行

Global site tag (gtag.js) - Google Analytics