zoukankan      html  css  js  c++  java
  • Heavy Transportation

    POJ - 1797 

    这题求:1到n的路径中,边权最小的定义是min,求出min的最大值)

     1 #include<iostream>
     2 #include<algorithm>
     3 #include<cstring>
     4 #include<cmath>
     5 #include<cstdio>
     6 using namespace std;
     7 
     8 const int INF=0x3f3f3f3f;
     9 int n,m;
    10 int e[1005][1005];
    11 
    12 int dijkstra()
    13 {
    14     int book[1005];
    15     int wei[1005];
    16     for(int i=1;i<=n;i++)
    17     {
    18         wei[i]=e[1][i];
    19         book[i]=0;
    20     }
    21     book[1]=1;
    22     wei[1]=0; //................
    23     
    24     int u;
    25     for(int i=2;i<=n;i++)
    26     {
    27         int temp=0;
    28         for(int j=1;j<=n;j++)
    29         {
    30             if(!book[j] && wei[j]>temp)
    31             {
    32                 u=j;
    33                 temp= wei[j];
    34             }
    35         }
    36         book[u]=1;
    37         
    38         for(int j=1;j<=n;j++)
    39         {
    40             if(!book[j] && wei[j]< min( e[j][u], wei[u]) ) 
    41                 wei[j]= min( e[j][u], wei[u]);
    42                 //更新,因为wei是储存1到每一个点的能通过的最大的重量
    43                 //所以要更新 使 j从1-n的 wei[j]比 “wei[u]和它下一段的e[u][j]其中一段的最小值 ” 的大, 
    44         }
    45     }
    46     return wei[n];
    47 
    48 }
    49 int main()
    50 {
    51     int cas=0;
    52     int a,b,w;
    53     int T; 
    54     scanf("%d",&T);
    55     for(int i=1;i<=T;i++)
    56     {
    57         memset(e,0,sizeof(e));
    58         scanf("%d%d",&n,&m);
    59         for(int i=1;i<=m;i++)
    60         {
    61             scanf("%d%d%d",&a,&b,&w);
    62             if( w >e[a][b])
    63                 e[a][b]=e[b][a]=w;
    64         }
    65         printf("Scenario #%d:
    %d
    
    ",++cas,dijkstra());
    66     }
    67 }
  • 相关阅读:
    staticmethod classmethod
    Cache Buffer 区别
    Apache 各启动方式的差别
    网段,掩码
    容器镜像国内下载加速----借助阿里
    import 本质
    数字签名证书的事儿
    java中的sql语句中如果有like怎么写
    VMware+centos7克隆多个虚拟机
    使用Ajax轮询模拟简单的站内信箱(消息管理)功能
  • 原文地址:https://www.cnblogs.com/thunder-110/p/9114533.html
Copyright © 2011-2022 走看看