zoukankan      html  css  js  c++  java
  • poj 1797 Heavy Transportation

                                                                       Heavy Transportation
     
    Time Limit: 3000MS   Memory Limit: 30000K
    Total Submissions: 17998   Accepted: 4750

    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
    ——-----------------

    水题。。1Y。。。300Ms,,ac、、、、

     1 #include<stdio.h>
     2 #include<string.h> 
     3 #define N 1010
     4 #define INF 1000010 
     5 
     6 int map[N][N],dis[N],vist[N],n; 
     7 void init ()
     8 {
     9     for(int i=1;i<=n;i++)
    10     for(int j=1;j<=n;j++)
    11     map[i][j]=map[j][i]=0; 
    12 }
    13 int kij ()
    14 {
    15     int i,j,k; 
    16     memset(vist,0,sizeof(vist));
    17     memset(dis,0,sizeof(dis)); 
    18     for(i=1;i<=n;i++)dis[i]=map[1][i]; 
    19     int min=INF; 
    20     for(i=1;i<=n;i++)
    21     {
    22         int max=0;
    23         for(j=2;j<=n;j++)
    24         {
    25             if(!vist[j]&&dis[j]>max)
    26             {
    27                 k=j;
    28                 max=dis[j]; 
    29             } 
    30         }
    31         vist[k]=1;
    32         if(max<min){min=max;}
    33         if(k==n)break; 
    34         for(j=2;j<=n;j++)
    35         {
    36             if(!vist[j]&&dis[j]<map[k][j])
    37             dis[j]=map[k][j]; 
    38         } 
    39     }
    40     return min; 
    41 } 
    42 int main ()
    43 {
    44     int T,i,j,m,a,b,len; 
    45     while(scanf("%d",&T)!=EOF)
    46     {
    47         for(int ca=1;ca<=T;ca++)
    48         {
    49             scanf("%d%d",&n,&m);
    50             init(); 
    51             for(i=1;i<=m;i++)
    52             {
    53                 scanf("%d%d%d",&a,&b,&len);
    54                 map[a][b]=map[b][a]=len; 
    55             } 
    56             printf("Scenario #%d:
    ",ca); 
    57             printf("%d
    
    ",kij()); 
    58         } 
    59     } 
    60 } 
  • 相关阅读:
    legend3---videojs存储视频的播放速率便于用户观看视频
    legend3---mathjax的动态渲染问题解决
    matplotlib库疑难问题---10、画直方图
    matplotlib库疑难问题---9、画箭头(综合实例)
    js释放图片资源
    javascript中的原型与原型链
    前端跨域方式
    matplotlib清除 axes 和 figure
    matplotlib画直方图细解
    CentOS 7.8 安装 Python 3.8.5
  • 原文地址:https://www.cnblogs.com/ace-top/p/3290154.html
Copyright © 2011-2022 走看看