题目大意:
输入
2 //代表2个案例
1 2 3 4 1 3 5 7 //// 案例1 代表l1---l4 c1 -- c4
4 2 4个站 2个问题 求2个路径
1
2
3
4
1 4 求1到4 的最小花费
4 1 求4到1的最小花费
1 2 3 4 1 3 5 7 /////案例2
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<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
const long long inf = 1e18;
const int N = 110;
typedef long long ll;
ll map[N][N];
ll x[N];
int n, m;
ll L1, L2, L3, L4, C1, C2, C3, C4;
void floyd(){
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++)
for(int k = 1; k <= n; k++)
map[j][k] = min(map[j][k], map[j][i] + map[i][k]);
}
ll getm(ll dis){
if(dis < 0) dis = -dis;
if(dis > 0 && dis <= L1) return C1;
if(dis > L1 && dis <= L2) return C2;
if(dis > L2 && dis <= L3) return C3;
if(dis > L3 && dis <= L4) return C4;
return inf;
}
int main(){
int t ;
scanf("%d", &t);
int tt = 0;
while(t--){
scanf("%lld%lld%lld%lld%lld%lld%lld%lld",&L1,&L2,&L3,&L4,&C1,&C2,&C3,&C4);
scanf("%d%d", &n, &m);
memset(map, inf, sizeof map);
for(int i = 1; i <= n; i++) scanf("%lld", &x[i]);
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++)
map[i][j] = map[j][i] = getm(x[i] - x[j]);
floyd();
cout << "Case " << ++tt << ":" << endl;
while(m--){
int u, v;
scanf("%d%d", &u, &v);
if(map[u][v] != inf) printf("The minimum cost between station %d and station %d is %lld.\n",u,v,map[u][v]);
else printf("Station %d and station %d are not attainable.\n",u,v);
}
}
return 0;
}