HUST 1408 公交系统

1408 - 公交系统

时间限制:1秒 内存限制:256兆

606 次提交 59 次通过
题目描述

因为中国人口众多,公共交通就显得很重要. 在传统城市公共交通系统中,公交车是一种很重要的工具。甚至现在还扮演了一种极其重要的角色。

X市的公交系统显得很独特。不像别的城市,该市公交系统是基于两站间的距离来计费的。下表描述了两站之间距离与费用的关系:

 

距离

费用

0<dist<=L1

C1

L1<dist<=L2

C2

L2<dist<=L3

C3

L3<dist<=L4

C4

dist>L4

没有这种票

表1

你的邻居是一位出名的吝啬鬼。他希望你能帮他计算出他列出表中两站间的最短花费,你能帮帮他吗?

为了简化这个问题,你可以假设所有的站都在一条直线上。我们仅用X坐标来描述每一个站的位置。

输入

输入文件包含多组数据。第一行包含一个整数T表示T组测试数据(T<=20)

每组数据第一行为8个数:L1, L2, L3, L4, C1, C2, C3, C4,每一个数都是不超过1,000,000,000的非负数,并且L1<=L2<=L3<=L4.

接下来两个整数n和m,表示n个站和m个询问。下面n行,每行一个数表示第i个站的x坐标。

下面m行,每行两个数表示询问的起点站和目标站。

在所有的询问中,起点站和目标站都不同。

对于每组数据有,2<=N<=100,0<=M<=500,每一个x坐标在-1,000,000,000 到1,000,000,000之间,并且没有两个x坐标相同。

输出

对于第T组测试数据第一行输出“Case T:”(没有引号)

对于每组询问,如果两个站可达,输出最小花费,否则输出“Station X and station Y are not attainable.”(没有引号)具体格式见样例。

样例输入
2
1 2 3 4 1 3 5 7
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
样例输出
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.
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#define N 1009
#define ll long long
#define INF 20000000000009
using namespace std;

ll l1,l2,l3,l4,c1,c2,c3,c4;
int n,m;
ll a[N];
ll mp[N][N];


int main()
{
    int t;
   scanf("%d",&t);
    {
        for(int ca=1;ca<=t;ca++)
        {
            printf("Case %d:\n",ca);

            scanf("%lld %lld %lld %lld %lld %lld %lld %lld",&l1,&l2,&l3,&l4,&c1,&c2,&c3,&c4);
            scanf("%d %d",&n,&m);

            for(int i=1;i<=n;i++)
            {
                for(int j=1;j<=n;j++)
                {
                    if(i==j) mp[i][j]=0;
                    else
                    mp[i][j]=INF;
                }
            }


            for(int i=1;i<=n;i++)
            {
                scanf("%lld",&a[i]);
                for(int j=1;j<i;j++)
                {
                    ll t=fabs(a[i]-a[j]);
                    ll xx=INF;
                    if(t>0 && t<=l1) xx=c1;
                    else if(t>l1 && t<=l2) xx=c2;
                    else if(t>l2 && t<=l3) xx=c3;
                    else if(t>l3 && t<=l4) xx=c4;

                    mp[i][j]=mp[j][i]=xx;
                }
            }

            for(int k=1;k<=n;k++)
            for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
            mp[i][j]=min(mp[i][j],mp[i][k]+mp[k][j]);

            for(int i=0;i<m;i++)
            {
                int x,y;
                scanf("%d %d",&x,&y);

                if(mp[x][y]<INF)
                printf("The minimum cost between station %d and station %d is %lld.\n",x,y,mp[x][y]);
                else
               printf("Station %d and station %d are not attainable.\n",x,y);


            }
        }
    }


    return 0;
}


比赛时候想成贪心了,但是不知道为啥一直RE,后来改了又PE,也是醉了,明明就是复制粘贴过来的文字。。。又重新复制粘贴一遍就过了。

最短路floyd。







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值