• poj 1797 Heavy Transportation


    和2253题类似,但所求正好相反。

    题意:有M条路连接N座城市,每条路都有最大载重量,要从城市1到到城市n求最大的载重量。

    思路:就是要求所有路中的最小值中的最大值,呃,将2253题的松弛条件改一下就行了。不多说了。

    代码:

    View Code
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <iostream>
    #include <algorithm>
    #include <math.h>
    #include <queue>
    #define  N 1004
    #define  INF 10000000
    using namespace std ;
    
    int map[N][N] , d[N] ;
    int f[N] ;
    int n , m ;
    
    void init()
    {
        memset( map , 0 , sizeof ( map )) ;
        memset( f , 0 , sizeof ( f )) ;
        memset( d , 0 , sizeof ( d )) ;
    }
    
    void dijskra( int s )
    {
        int  i , j , pos ;
        int min_t ;
        d[1] = INF ;
        f[1] = 1 ;
        for ( i = 1 ; i < n ; i++ )
        {
            min_t = 0 ;
            for ( j = 1 ; j <= n ; j++ )
            if ( !f[j] )
            {
                //这里改变一下松弛条件,dis[i]中存储经过它的所有路径中的最小值。
                if ( map[j][s] && d[j] < min ( d[s] , map[j][s] ))
                d[j] = min ( d[s] , map[j][s] );
                if ( min_t < d[j] )
                {
                    min_t = d[j] ;
                    pos = j ;
                }
            }
            if ( pos == n )
            return ;
            s = pos ;
            f[pos] = 1 ;
        }
    }
    
    
    int main()
    {
        int i , x , y , z ;
        int cas , c ;
    
        scanf ( "%d" , &cas ) ;
        for ( c = 1 ; c <= cas ; c++ )
        {
            scanf ( "%d%d" , &n , &m );
    
            init();
            for ( i = 1 ; i <= m ; i++ )
            {
                scanf ( "%d%d%d" , &x , &y , &z ) ;
                if ( map[x][y] < z )
                map[x][y] = map[y][x] = z ;
            }
            //init();
            dijskra( 1 ) ;
            printf ( "Scenario #%d:\n%d\n\n" , c , d[n] );
        }
        return 0 ;
    }
  • 相关阅读:
    axios
    vue-cli-service 报错
    避免大型、复杂的布局和布局抖动
    vue 父子通信
    == 区别 === ,!= 区别 !==
    全选/取消全选
    vue 注意
    pyparsing:自定义一个属于你的语法解析器(更新中)
    《python解释器源码剖析》第11章--python虚拟机中的控制流
    collections:内建模块,提供额外的集合类
  • 原文地址:https://www.cnblogs.com/misty1/p/2732755.html
Copyright © 2020-2023  润新知