HDU1690

题目大意:
在这里插入图片描述
输入

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 414 的最小花费
4 141的最小花费
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;
}
发布了28 篇原创文章 · 获赞 22 · 访问量 1019

猜你喜欢

转载自blog.csdn.net/qq_45432665/article/details/103929371
hdu