zoukankan      html  css  js  c++  java
  • hdu 1690 Bus System

    http://acm.hdu.edu.cn/showproblem.php?pid=1690

     1 #include <cstdio>
     2 #include <iostream>
     3 #include <cstring>
     4 #include <cmath>
     5 #include <algorithm>
     6 #define maxn 500
     7 #define LL __int64
     8 using namespace std;
     9 const LL inf=999999999999;
    10 
    11 LL L1,L2,L3,L4,C1,C2,C3,C4;
    12 LL g[maxn][maxn];
    13 LL a[maxn];
    14 int n,m;
    15 LL st,ed;
    16 
    17 LL Abs(LL x)
    18 {
    19     if(x<0) return -x;
    20     return x;
    21 }
    22 
    23 LL judge(LL x)
    24 {
    25     if(x>0&&x<=L1) return C1;
    26     else if(x>L1&&x<=L2) return C2;
    27     else if(x>L2&&x<=L3) return C3;
    28     else if(x>L3&&x<=L4) return C4;
    29     else return inf;
    30 }
    31 
    32 void floyd()
    33 {
    34     for(int k=0; k<n; k++)
    35     {
    36         for(int i=0; i<n; i++)
    37         {
    38             if(g[i][k]==inf) continue;
    39             for(int j=0; j<n; j++)
    40             {
    41                 if(g[i][j]>g[i][k]+g[k][j])
    42                     g[i][j]=g[i][k]+g[k][j];
    43             }
    44         }
    45     }
    46 }
    47 
    48 int main()
    49 {
    50     int t;
    51     scanf("%d",&t);
    52     for(int case1=1; case1<=t; case1++)
    53     {
    54         cin>>L1>>L2>>L3>>L4>>C1>>C2>>C3>>C4;
    55         cin>>n>>m;
    56         for(int i=0; i<n; i++)
    57         {
    58             for(int j=0; j<n; j++)
    59             {
    60                 if(i==j) g[i][j]=0;
    61                 else g[i][j]=inf;
    62             }
    63         }
    64         for(int i=0; i<n; i++)
    65         {
    66             cin>>a[i];
    67         }
    68         for(int i=0; i<n; i++)
    69         {
    70             for(int j=i+1; j<n; j++)
    71             {
    72                 g[i][j]=g[j][i]=judge(Abs(a[i]-a[j]));
    73             }
    74         }
    75         floyd();
    76         printf("Case %d:
    ",case1);
    77         for(int i=0; i<m; i++)
    78         {
    79             cin>>st>>ed;
    80             if(g[st-1][ed-1]!=inf)
    81             printf("The minimum cost between station %I64d and station %I64d is %I64d.
    ",st,ed,g[st-1][ed-1]);
    82             else
    83                 printf("Station %I64d and station %I64d are not attainable.
    ",st,ed);
    84         }
    85     }
    86     return 0;
    87 }
    View Code
  • 相关阅读:
    函数与方法(方法前 +
    1362 : 修补木桶 -- 最长的最短边
    149. Max Points on a Line *HARD* 求点集中在一条直线上的最多点数
    148. Sort List -- 时间复杂度O(n log n)
    133. Clone Graph 138. Copy List with Random Pointer 拷贝图和链表
    debug && release
    静态库 && 动态库
    枚举
    获取当前用户所使用的是什么浏览器
    java实现在图片上编辑文本内容
  • 原文地址:https://www.cnblogs.com/fanminghui/p/3712314.html
Copyright © 2011-2022 走看看