Problem:
Link: Click to open the link
Question:
Ideas:
Code:
# Include <iostream> # include <cstdio> # include <cstring> using namespace STD; # define INF 1000000000000 typedef _ int64 ll; const int n = 110; __int64 dis [N] [N], place [N] ;__ int64 L1, L2, L3, L4, C1, C2, C3, C4; int n, m; ll judge (ll x) {If (x <0) x * =-1; if (x> 0 & x <= L1) return C1; else if (x> L1 & x <= l2) return C2; else if (x> L2 & x <= l3) return C3; else if (x> L3 & x <= L4) return C4; else return INF ;} Void Floyd () {for (int K = 1; k <= N; k ++) {for (INT I = 1; I <= N; I ++) {for (Int J = 1; j <= N; j ++) {If (DIS [I] [J]> dis [I] [k] + dis [k] [J] & dis [I] [k]! = Inf & dis [k] [J]! = Inf) dis [I] [J] = dis [I] [k] + dis [k] [J] ;}}} int main () {// freopen ("input.txt", "r", stdin); int t; int Kase = 1; CIN> T; while (t --) {scanf ("% i64d % i64d % i64d % i64d % i64d % i64d % i64d % i64d", & L1, & L2, & L3, & L4, & C1, & C2, & C3, & C4); scanf ("% d", & N, & M); For (INT I = 1; I <= N; I ++) {scanf ("% i64d", & place [I]) ;}for (INT I = 1; I <= N; I ++) {for (Int J = I + 1; j <= N; j ++) {_ int64 x = place [I]-place [J]; dis [I] [J] = dis [J] [I] = Judge (x) ;}} Floyd (); printf ("case % d: \ n", Kase ++); For (INT I = 1; I <= m; I ++) {int St, Ed; scanf ("% d", & St, & ED ); if (DIS [st] [ed]! = Inf) printf ("the minimum cost between station % d and station % d is % i64d. \ n ", St, Ed, DIS [st] [ed]); else printf (" station % d and station % d are not attainable. \ n ", St, Ed) ;}} return 0 ;}
----------------------------------------------------------
Gains:
---------------------------------------------------------
Fighting, never shrinking; fighting, never stopping ~~~~~~~~~~~~~~