• POJ-1797 Heavy Transportation( 最短路 )


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

    Description

    Background
    Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand business. But he needs a clever man who tells him whether there really is a way from the place his customer has build his giant steel crane to the place 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 and all the allowed weights.Unfortunately he has no idea how to find the the maximum weight capacity in order to tell his customer how heavy the crane may become. But you surely know.

    Problem
    You are given the plan of the city, described by the streets (with weight limits) between the crossings, which are numbered from 1 to n. Your task is to find 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 one path. All streets can be travelled in both directions.

    Input

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

    Output

    The output for every scenario begins with a line containing "Scenario #i:", where i is the number of the scenario starting at 1. Then print a single line containing the maximum allowed weight that Hugo can transport to the customer. Terminate the output for 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

    题目大意:一个人要从1号路口送货到n号路口,但是每条路都有载重限制,问这个人最多能送多重的货物
    解题思路:最短路,将判断条件改为每条路的负重即可

     1 #include<iostream>
     2 #include<cstring>
     3 #include<algorithm>
     4 #include<cmath>
     5 #include<iomanip>
     6 #include<map>
     7 
     8 using namespace std;
     9 
    10 int street[1005][1005], dis[1005];
    11 bool flag[1005];
    12 
    13 int main(){
    14     ios::sync_with_stdio( false );
    15 
    16     int T, n, m, x, y, temp;
    17     cin >> T;
    18     for( int t = 1; t <= T; t++ ){
    19         cin >> n >> m;
    20         memset( street, -1, sizeof( street ) );
    21         memset( flag, true, sizeof( flag ) );
    22         for( int i = 0; i < m; i++ ){
    23             cin >> x >> y >> temp;
    24             street[x][y] = street[y][x] = temp;
    25         }
    26         for( int i = 2; i <= n; i++ ){
    27             dis[i] = street[1][i];
    28         }
    29 
    30         for( int k = 1; k < n; k++ ){
    31             int maxx = -1, maxi = 1;
    32             for( int i = 2; i <= n; i++ ){
    33                 if( flag[i] && dis[i] > maxx ){
    34                     maxx = dis[i];
    35                     maxi = i;
    36                 }
    37             }
    38 
    39             flag[maxi] = false;
    40 
    41             for( int i = 2; i <= n; i++ ){
    42                 if( flag[i] && dis[i] < min( dis[maxi], street[maxi][i] ) ){
    43                     dis[i] = min( dis[maxi], street[maxi][i] );
    44                 }
    45             }
    46         }
    47 
    48         cout << "Scenario #" << t << ":" << endl << dis[n] << endl << endl;
    49     }
    50 
    51     return 0;
    52 }
  • 相关阅读:
    as3 的相关资源
    linux 进程用户栈和内核栈
    Chapter 11 进程与信号 @ linux
    linux/unix下setuid/seteuid/setreuid/setresuid
    poj 3259 spfa 虫洞问题判到点1时候有环
    My Vimrc Archive
    C/C++函数调用的几种方式
    Git常用命令解说 [robby certification]
    Linux Chapter 11 进程与信号
    XNA游戏开发之(四)——改变Draw频率
  • 原文地址:https://www.cnblogs.com/hollowstory/p/5584138.html
Copyright © 2020-2023  润新知