zoukankan      html  css  js  c++  java
  • HDU 1690 最短路

     1 #include<stdio.h>
     2 #include<string.h>
     3 #include<queue>
     4 #include<algorithm>
     5 using namespace std;
     6 
     7 typedef __int64 ll;
     8 #define inf 0x3f3f3f3f
     9 //#define inf 0x7f7f7f7f7f7f7f7fLL
    10 #define min(x,y) (x<y?x:y)
    11 ll l1,l2,l3,l4,c1,c2,c3,c4;
    12 int n,m;
    13 ll x[102];
    14 ll dist[102][102];
    15 
    16 void floyd(){
    17     for(int k=1;k<=n;k++){
    18         for(int i=1;i<=n;i++){
    19             for(int j=1;j<=n;j++){
    20                 if(dist[i][k]==inf||dist[k][j]==inf){
    21                     continue;
    22                 }
    23                 ll res=dist[i][k]+dist[k][j];
    24                 if(res<dist[i][j]){
    25                     dist[i][j]=res;
    26                 }
    27             }
    28         }
    29     }
    30 }
    31 
    32 int main(){
    33     int T;
    34     scanf("%d",&T);
    35     for(int t=1;t<=T;t++){
    36         scanf("%I64d%I64d%I64d%I64d%I64d%I64d%I64d%I64d",&l1,&l2,&l3,&l4,&c1,&c2,&c3,&c4);
    37         scanf("%d%d",&n,&m);
    38         for(int i=1;i<=n;i++){
    39             scanf("%I64d",&x[i]);
    40         }
    41         for(int i=1;i<=n;i++){
    42             for(int j=i+1;j<=n;j++){
    43                 ll d=x[i]-x[j];
    44                 if(d<0){
    45                     d*=-1;
    46                 }
    47                 if(0<d&&d<=l1){
    48                         dist[i][j]=dist[j][i]=c1; 
    49                 }
    50                 else if(l1<d&&d<=l2){
    51                     dist[i][j]=dist[j][i]=c2; 
    52                 }
    53                 else if(l2<d&&d<=l3){
    54                     dist[i][j]=dist[j][i]=c3; 
    55                 }
    56                 else if(l3<d&&d<=l4){
    57                     dist[i][j]=dist[j][i]=c4;
    58                 }
    59                 else{
    60                     dist[i][j]=dist[j][i]=inf;
    61                 }
    62             }
    63         }
    64         floyd();
    65         printf("Case %d:
    ",t);
    66         for(int i=0;i<m;i++){
    67             int a,b;
    68             scanf("%d%d",&a,&b);
    69             if(dist[a][b]==inf){
    70                     printf("Station %d and station %d are not attainable.
    ",a,b);
    71             }
    72             else{
    73                 printf("The minimum cost between station %d and station %d is %I64d.
    ",a,b,dist[a][b]);
    74             }
    75         }
    76     }
    77 }
  • 相关阅读:
    VSCode 配置 Python 开发环境
    出现:Microsoft Visual C++ 14.0 is required 的解决方案
    python3 pathlib库中的Path类的使用
    使用 AI 绘制箭头
    Adobe Illustrator 入门 新建 保存图片
    jinja2
    Java 读取和写入文本文件
    Affy包 estrogen包
    GEOquery
    apply() 函数家族介绍
  • 原文地址:https://www.cnblogs.com/Stomach-ache/p/3703200.html
Copyright © 2011-2022 走看看