水題直接貼代碼
#include#include #include #include #include #include #include #include using namespace std; #define maxn 1200 #define LL __int64 const LL INF = 100000000002; LL sit[maxn]; LL dis[maxn][maxn]; int main() { #ifdef xxz freopen("in.txt","r",stdin); #endif // xxz LL Case,L1,L2,L3,L4,C1,C2,C3,C4,n,m,v,T; cin>>T; Case = 1; while(T--) { cin>>L1>>L2>>L3>>L4>>C1>>C2>>C3>>C4; cin>>n>>m; for(LL i = 1; i <= n; i++) { cin>>sit[i]; dis[i][i] = 0; for(LL j = 1; j < i; j++ ) { LL temp = max(sit[i],sit[j]) - min(sit[i],sit[j]); if(temp > L4) v = INF; else if(temp > L3) v = C4; else if(temp > L2) v= C3; else if(temp > L1) v = C2; else if(temp > 0) v = C1; else v = 0; dis[i][j] = dis[j][i] = v; } } for(LL k = 1; k <= n; k++) for(LL i = 1; i <= n; i++) for(LL j = 1; j<= n; j++) { dis[i][j] = min(dis[i][j],dis[i][k] + dis[k][j]); } printf("Case %d:\n",Case++); for(LL i = 0; i < m; i++) { LL a,b; cin>>a>>b; if(dis[a][b]== INF ) printf("Station %I64d and station %I64d are not attainable.\n",a,b); else printf("The minimum cost between station %I64d and station %I64d is %I64d.\n",a,b,dis[a][b]); } } return 0; }