poj_1797 Heavy Transportation

本文探讨了深度学习在图像处理领域的应用,包括AR特效、图像处理、音视频直播等场景,详细介绍了如何利用深度学习算法实现图像的美颜、剪辑、分割、人像追踪等功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Heavy Transportation

Time Limit: 3000MS

Memory Limit: 30000K

Total Submissions: 15487

Accepted: 4026

题目链接http://poj.org/problem?id=1797

Description

Background
Hugo Heavy is happy. After the breakdown of the Cargolifter project he can nowexpand business. But he needs a clever man who tells him whether there reallyis a way from the place his customer has build his giant steel crane to theplace where it is needed on which all streets can carry the weight.
Fortunately he already has a plan of the city with all streets and bridges andall the allowed weights.Unfortunately he has no idea how to find the themaximum weight capacity in order to tell his customer how heavy the crane maybecome. But you surely know.

Problem
You are given the plan of the city, described by the streets (with weightlimits) between the crossings, which are numbered from 1 to n. Your task is tofind the maximum weight that can be transported from crossing 1 (Hugo's place)to crossing n (the customer's place). You may assume that there is at least onepath. All streets can be travelled in both directions.

Input

The first line contains thenumber of scenarios (city plans). For each city the number n of streetcrossings (1 <= n <= 1000) and number m of streets are given on the firstline. The following m lines contain triples of integers specifying start andend crossing of the street and the maximum allowed weight, which is positive andnot larger than 1000000. There will be at most one street between each pair ofcrossings.

Output

The output for every scenariobegins with a line containing "Scenario #i:", where i is the numberof the scenario starting at 1. Then print a single line containing the maximumallowed weight that Hugo can transport to the customer. Terminate the outputfor the scenario with a blank line.

Sample Input

1

3 3

1 2 3

1 3 4

2 3 5

Sample Output

Scenario #1:

4

Source

TUDProgramming Contest 2004, Darmstadt, Germany

题意:

求图中第一点到最后一点的每一条路径中最小值,然后这这些路径的最小值中在找出最大值,这个题目不好理解,所先理解成了求最短路径的最大边,后来有理解成了求最长路径的最短边,都理解错了,这个题目理解对了就不难做了,用Dijkstra算法求出第一点到最后一点的每一条路径的最小值放在数组中,在求数组中的最大值即可。

代码:

//求解从第一点到达最后一点的最小生成树的最大值
#include <iostream>
#include<cstdio>
#include<cstring>
#define MAX 12
#define VALUE 0x3f3f3f3f
using namespace std;


int n,m;//n个节点,m条边
int g[MAX][MAX];
int used[MAX];
int d[MAX];

int minValue(int a,int b)
{
	if(a>b)
		return b;
	return a;
}

int Dijkstra()
{
    int i;
	int pre=1;
	memset(used,0,sizeof(used));
	memset(d,0,sizeof(d));//第一点到最后一点的距离都置为0
	used[1]=true;
	d[1]=VALUE;
	while(true)
	{
		for(i=1;i<=n;i++)
		{
			if(!used[i] && minValue(d[pre],g[pre][i])>d[i])
				d[i]=minValue(d[pre],g[pre][i]);
		}
		int a=-1,b=-1;
		for(i=1;i<=n;i++)
		{//遍历每一个点,如果该点没被访问过,并且从第一点到第i点的距离大于最大距离,记录该点编号i
			if(!used[i] && d[i]>a)
			{
				a=d[i];
				b=i;
			}
		}
		if(b==-1)
			break;
		used[b]=true;
		pre=b;
	}
    return d[n];
}

int main()
{
    int ts;
    int i,j;
    int start,end,weight;
    scanf("%d",&ts);
    for(j=1;j<=ts;j++)
    {
        scanf("%d%d",&n,&m);
        memset(g,0,sizeof(g));
        for(i=0;i<m;i++)
        {
            scanf("%d%d%d",&start,&end,&weight);
            g[start][end]=weight;
            g[end][start]=weight;
        }
        printf("Scenario #%d:\n",j);
        printf("%d\n\n",Dijkstra());

    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值