• hdu 1690 构图后Floyd 数据很大


    WA了好多次... 这题要用long long 而且INF要设大一点

    Sample Input
    2 //T
    1 2 3 4 1 3 5 7 //L1-L4 C1-C4 距离和花费
    4 2 //结点数 询问次数
    1 //结点的横坐标
    2
    3
    4
    1 4 //起点 终点
    4 1
    1 2 3 4 1 3 5 7
    4 1
    1
    2
    3
    10
    1 4

    Sample Output
    Case 1:
    The minimum cost between station 1 and station 4 is 3.
    The minimum cost between station 4 and station 1 is 3.
    Case 2:
    Station 1 and station 4 are not attainable.

     1 # include <iostream>
     2 # include <cstdio>
     3 # include <cstring>
     4 # include <algorithm>
     5 # include <cmath>
     6 # include <queue>
     7 # define LL long long
     8 using namespace std ;
     9 
    10 const LL INF=0x7f7f7f7f7f7f7f7fLL;
    11 const int MAXN=210;
    12 
    13 LL L[10] ;
    14 LL C[10] ;
    15 LL x[MAXN] ;
    16 
    17 LL dis[MAXN][MAXN];
    18 int n ;
    19 
    20 
    21 void floyed()//节点从1~n编号
    22 {
    23     int i,j,k;
    24     for(k=1;k<=n;k++)
    25        for(i=1;i<=n;i++)
    26          for(j=1;j<=n;j++)
    27              if(dis[i][k]+dis[k][j] < dis[i][j] && dis[i][k] != INF && dis[k][j] != INF)
    28                  dis[i][j]=dis[i][k]+dis[k][j];
    29 
    30 }
    31 
    32 LL Cost(LL d)
    33 {
    34     if (d < 0)
    35         d *= -1 ;
    36     if (d > 0 && d<= L[1])
    37         return C[1] ;
    38     if (d > L[1] && d<= L[2])
    39         return C[2] ;
    40     if (d > L[2] && d<= L[3])
    41         return C[3] ;
    42     if (d > L[3] && d<= L[4])
    43         return C[4] ;
    44     return INF ;
    45 }
    46 
    47 int main ()
    48 {
    49    // freopen("in.txt","r",stdin) ;
    50     int cnt ;
    51     int T ;
    52     cin>>T ;
    53     int Case = 0 ;
    54     while (T--)
    55     {
    56         Case++ ;
    57         cout<<"Case "<<Case<<":"<<endl ;
    58         int i , j  ;
    59         LL w ;
    60         for (i = 1 ; i <= 4 ; i++)
    61             cin>>L[i];
    62         for (i = 1 ; i <= 4 ; i++)
    63             cin>>C[i];
    64 
    65         cin>>n>>cnt ;
    66         for (i = 1 ; i <= n ; i++)
    67             cin>>x[i];
    68         for (i = 1 ; i <= n ; i++)
    69             for (j = 1 ; j <= n ; j++)
    70           {
    71               if(i==j)dis[i][j]=0;
    72               else dis[i][j]=INF;
    73           }
    74         for (i = 1 ; i <= n ; i++)
    75             for (j = i+1 ; j <= n ; j++)
    76         {
    77             LL d = x[i] - x[j] ;
    78             w = Cost(d) ;
    79             dis[i][j] = w ;
    80             dis[j][i] = w ;
    81         }
    82         floyed() ;
    83         int u , v ;
    84         while(cnt--)
    85         {
    86             cin>>u>>v ;
    87             if (dis[u][v] != INF)
    88               cout<<"The minimum cost between station "<<u<<" and station "<<v<<" is "<<dis[u][v]<<"."<<endl ;
    89             else
    90               cout<<"Station "<<u<<" and station "<<v<<" are not attainable."<<endl ;
    91         }
    92     }
    93 
    94     return 0 ;
    95 }
    View Code
  • 相关阅读:
    WCF 4.0中的动态发现服务WSDiscovery
    Windows Server 2008 R2 Server Core
    Open Source Web Design
    Windows Identity Foundation(WIF)正式发布
    是开始学习IronPython 的时候了
    IronPython 承载和消费WCF服务
    微博客程序 Yonkly
    如何启用匿名访问SQL Server Reporting Service 2008
    ASP.NET MVC 2 RC 发布
    SharePoint 2010 VHD下载
  • 原文地址:https://www.cnblogs.com/mengchunchen/p/4591764.html
Copyright © 2020-2023  润新知