zoukankan      html  css  js  c++  java
  • pku3615 Cow Hurdles

    http://poj.org/problem?id=3615

    图论,最短路,DP,floyd

     1 #include <stdio.h>
     2 #define N 321
     3 
     4 const int inf = 1<<29;
     5 int n, g[N][N];
     6 
     7 int min(int x, int y)
     8 {
     9     return x<y? x: y;
    10 }
    11 
    12 int max(int x, int y)
    13 {
    14     return x>y? x: y;
    15 }
    16 
    17 void floyd()
    18 {
    19     for(int k=1; k<=n; k++)
    20     {
    21         for(int i=1; i<=n; i++)
    22         {
    23             for(int j=1; j<=n; j++)
    24             {
    25                 g[i][j] = min(g[i][j], max(g[i][k], g[k][j]));
    26             }
    27         }
    28     }
    29 }
    30 
    31 int main()
    32 {
    33     int m, t, i, j, x, y, len;
    34     scanf("%d%d%d", &n, &m, &t);
    35     for(i=1; i<=n; i++)
    36     {
    37         for(j=1; j<=n; j++)
    38         {
    39             g[i][j] = inf;
    40         }
    41     }
    42     for(i=1; i<=m; i++)
    43     {
    44         scanf("%d%d%d", &x, &y, &len);
    45         g[x][y] = len;
    46     }
    47     floyd();
    48     for(i=1; i<=t; i++)
    49     {
    50         scanf("%d%d", &x, &y);
    51         printf("%d\n", g[x][y]==inf? -1: g[x][y]);
    52     }
    53     return 0;
    54 }
  • 相关阅读:
    天兔监控系统安装
    day6
    day5
    day4
    day3
    day2
    day1
    几个重要的Xenomai相关链接
    树莓派GPIO中断驱动程序
    转了一圈,再读LKD
  • 原文地址:https://www.cnblogs.com/yuan1991/p/pku3615.html
Copyright © 2011-2022 走看看