hdu 1690 Bus System

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
const __int64 inf=1e18;
const __int64 N=100+5;

__int64 edge[N][N],use[N],g[N],l1,l2,l3,l4,c1,c2,c3,c4,n,m;


__int64 getsum(__int64 x,__int64 y)
{
    __int64 t;
    if(x-y<0) t=y-x;
    else t=x-y;
    if(t==0) return 0;
    if(t>l4) return -1;
    else if(t<=l4&&t>l3) return c4;
    else if(t<=l3&&t>l2) return c3;
    else if(t<=l2&&t>l1) return c2;
    else return c1;
}

void floyd()
{
    __int64 i,j,k;
    for(k=0; k<n; k++)
    {
        for(i=0; i<n; i++)
        {
            for(j=0; j<n; j++)
            {
                if(edge[i][k]>=inf||edge[k][j]>=inf) continue;
                edge[i][j]=min(edge[i][j],edge[i][k]+edge[k][j]);
            }
        }
    }
}
int main()
{
    __int64 ans,_,t,k,i,j,x,y;
    scanf("%I64d",&_);
    for(t=1; t<=_; t++)
    {
        scanf("%I64d%I64d%I64d%I64d %I64d%I64d%I64d%I64d",&l1,&l2,&l3,&l4,&c1,&c2,&c3,&c4);
        for(i=0; i<N; i++)
            for(j=0; j<N; j++)
            {
                if(i==j) edge[i][j]=0;
                else edge[i][j]=inf;
            }

        scanf("%I64d%I64d",&n,&m);
        for(i=0; i<n; i++)
        {
            scanf("%I64d",&g[i]);
        }

        for(i=0;i<n;i++)
            for(j=0;j<n;j++)
        {
            if(getsum(g[i],g[j])==-1) continue;
            edge[i][j]=min(getsum(g[i],g[j]),edge[i][j]);
        }
        floyd();
        printf("Case %I64d:\n",t);
        for(i=0; i<m; i++)
        {
            scanf("%I64d%I64d",&x,&y);
            if(edge[x-1][y-1]>=inf) printf("Station %I64d and station %I64d are not attainable.\n",x,y);
            else printf("The minimum cost between station %I64d and station %I64d is %I64d.\n",x,y,edge[x-1][y-1]);
        }
    }
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。http://xiang578.top/

posted @ 2015-06-12 12:12  xryz  阅读(159)  评论(0编辑  收藏  举报