程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> HDU1690(Floyd最短路)

HDU1690(Floyd最短路)

編輯:C++入門知識

HDU1690(Floyd最短路)


水題直接貼代碼

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;

#define maxn 1200
#define LL __int64
const LL  INF = 100000000002;
LL sit[maxn];
LL dis[maxn][maxn];
int  main()
{
#ifdef xxz
    freopen("in.txt","r",stdin);
#endif // xxz
    LL Case,L1,L2,L3,L4,C1,C2,C3,C4,n,m,v,T;
    cin>>T;
    Case = 1;
    while(T--)
    {
        cin>>L1>>L2>>L3>>L4>>C1>>C2>>C3>>C4;
        cin>>n>>m;
        for(LL i = 1; i <= n; i++)
        {
            cin>>sit[i];
            dis[i][i] = 0;
            for(LL j = 1; j < i; j++ )
            {
                LL temp = max(sit[i],sit[j]) - min(sit[i],sit[j]);
                if(temp > L4)  v = INF;
                else if(temp > L3) v = C4;
                else if(temp > L2) v= C3;
                else if(temp > L1) v = C2;
                else if(temp > 0) v = C1;
                else v = 0;
                dis[i][j] = dis[j][i] = v;
            }
        }

        for(LL k = 1; k <= n; k++)
            for(LL i = 1; i <= n; i++)
                for(LL j = 1; j<= n; j++)
                {
                    dis[i][j] = min(dis[i][j],dis[i][k] + dis[k][j]);
                }
        printf("Case %d:\n",Case++);
        for(LL i = 0; i < m; i++)
        {
            LL a,b;
            cin>>a>>b;
            if(dis[a][b]== INF ) printf("Station %I64d and station %I64d are not attainable.\n",a,b);
            else printf("The minimum cost between station %I64d and station %I64d is %I64d.\n",a,b,dis[a][b]);
        }
    }
    return 0;
}


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved