题意: 坐公交 长度不同 票价不同
首先输入8个数L1 L2 L3 L4 C1 C2 C3 C4代表如果长度在 0-L1 花费 C1 L1-L2 花费C2 .... 超过L4 人家不拉你 - -
再输入n m 代表n个站 m个询问
接下来m行 每行两个数 代表所求的两点之间最短费用
最短路问题 由于点数只有100 所以直接Floyed即可
这题有个大坑... 不能再用1e9表示INF了 由于最大票价是1e9 所以我定义 INF = 2e9 很得意的认为自己发现了一个坑 然后就交了 无限WA - -! 但其实这是任意两站之间的 而实际有可能每两站之间都是INF 这样 总的票价可能达到 100×INF !!
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdlib>
using namespace std;
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define REV(i, a, b) for(int i = b; i >= a; i--)
typedef long long LL;
const int maxn = 100 + 10;
const LL INF = 1LL<<40;
LL dist[maxn][maxn];
int n, m, cas = 0;
LL L[6], C[6], s[maxn];
pair<int, int> q[maxn*5];
void input(){
L[0] = -1; C[0] = 0;
L[1] = 0; C[5] = INF;
FOR(i, 2, 5) scanf("%lld", &L[i]);
FOR(i, 1, 4) scanf("%lld", &C[i]);
scanf("%d%d", &n, &m);
FOR(i, 1, n) scanf("%lld", &s[i]);
FOR(i, 1, m) scanf("%d%d", &q[i].first, &q[i].second);
}
void solve(){
FOR(i, 1, n) FOR(j, 1, n) dist[i][j] = INF;
FOR(i, 1, n) FOR(j, 1, n){
int dis = abs(s[i] - s[j]);
REV(k, 0, 5) if(dis > L[k]){
dist[i][j] = C[k];
break;
}
}
FOR(k, 1, n) FOR(i, 1, n) FOR(j, 1, n)
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
printf("Case %d:\n", ++cas);
FOR(i, 1, m){
LL d = dist[q[i].first][q[i].second];
if(d < INF)
printf("The minimum cost between station %d and station %d is %lld.\n", q[i].first, q[i].second, d);
else
printf("Station %d and station %d are not attainable.\n", q[i].first, q[i].second);
}
}
int main()
{
// freopen("in.txt", "r", stdin);
int T;
scanf("%d", &T);
while(T--){
input();
solve();
}
return 0;
}