0
点赞
收藏
分享

微信扫一扫

HUST 1408 公交系统

花明 2022-11-10 阅读 81


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

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

 

距离

费用

0<dist<=L1

C1

L1<dist<=L2

C2

L2<dist<=L3

C3

L3<dist<=L4

C4

dist>L4

没有这种票

表1

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

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

Input

输入文件包含多组数据。第一行包含一个整数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坐标相同。

Output

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

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

Sample Input

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

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.


最短路,数据比较小直接上floyd即可,注意答案会爆int

#include<set>
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<bitset>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
#define rep(i,j,k) for (int i = j; i <= k; i++)
#define per(i,j,k) for (int i = j; i >= k; i--)
using namespace std;
typedef long long LL;
const int low(int x) { return x&-x; }
const double eps = 1e-5;
const int mod = 1e9 + 7;
const int N = 1e3 + 10;
const int INF = 0x7FFFFFFF;
int T, n, m, x, y, f[N], a[N], b[N], cas = 0;
LL d[N][N];

int get(int x)
{
rep(i, 0, 4) if (x <= a[i]) return b[i];
return -1;
}

int main()
{
scanf("%d", &T);
while (T--)
{
rep(i, 1, 4) scanf("%d", &a[i]);
rep(i, 1, 4) scanf("%d", &b[i]);
scanf("%d%d", &n, &m);
rep(i, 1, n)
{
scanf("%d", &f[i]);
rep(j, 1, i - 1)
{
d[i][j] = d[j][i] = get(abs(f[i] - f[j]));
}
}
rep(i, 1, n) rep(j, 1, n) rep(k, 1, n)
{
if (~d[j][i] && ~d[i][k] && (d[j][k] == -1 || d[j][k] > d[j][i] + d[i][k]))
{
d[j][k] = d[j][i] + d[i][k];
}
}
printf("Case %d:\n", ++cas);
while (m--)
{
scanf("%d%d", &x, &y);
if (d[x][y] == -1) printf("Station %d and station %d are not attainable.\n", x, y);
else printf("The minimum cost between station %d and station %d is %lld.\n", x, y, d[x][y]);
}
}
return 0;
}


举报

相关推荐

0 条评论