HDU 1690 最短路

 1 #include<stdio.h>

 2 #include<string.h>

 3 #include<queue>

 4 #include<algorithm>

 5 using namespace std;

 6 

 7 typedef __int64 ll;

 8 #define inf 0x3f3f3f3f

 9 //#define inf 0x7f7f7f7f7f7f7f7fLL

10 #define min(x,y) (x<y?x:y)

11 ll l1,l2,l3,l4,c1,c2,c3,c4;

12 int n,m;

13 ll x[102];

14 ll dist[102][102];

15 

16 void floyd(){

17     for(int k=1;k<=n;k++){

18         for(int i=1;i<=n;i++){

19             for(int j=1;j<=n;j++){

20                 if(dist[i][k]==inf||dist[k][j]==inf){

21                     continue;

22                 }

23                 ll res=dist[i][k]+dist[k][j];

24                 if(res<dist[i][j]){

25                     dist[i][j]=res;

26                 }

27             }

28         }

29     }

30 }

31 

32 int main(){

33     int T;

34     scanf("%d",&T);

35     for(int t=1;t<=T;t++){

36         scanf("%I64d%I64d%I64d%I64d%I64d%I64d%I64d%I64d",&l1,&l2,&l3,&l4,&c1,&c2,&c3,&c4);

37         scanf("%d%d",&n,&m);

38         for(int i=1;i<=n;i++){

39             scanf("%I64d",&x[i]);

40         }

41         for(int i=1;i<=n;i++){

42             for(int j=i+1;j<=n;j++){

43                 ll d=x[i]-x[j];

44                 if(d<0){

45                     d*=-1;

46                 }

47                 if(0<d&&d<=l1){

48                         dist[i][j]=dist[j][i]=c1; 

49                 }

50                 else if(l1<d&&d<=l2){

51                     dist[i][j]=dist[j][i]=c2; 

52                 }

53                 else if(l2<d&&d<=l3){

54                     dist[i][j]=dist[j][i]=c3; 

55                 }

56                 else if(l3<d&&d<=l4){

57                     dist[i][j]=dist[j][i]=c4;

58                 }

59                 else{

60                     dist[i][j]=dist[j][i]=inf;

61                 }

62             }

63         }

64         floyd();

65         printf("Case %d:\n",t);

66         for(int i=0;i<m;i++){

67             int a,b;

68             scanf("%d%d",&a,&b);

69             if(dist[a][b]==inf){

70                     printf("Station %d and station %d are not attainable.\n",a,b);

71             }

72             else{

73                 printf("The minimum cost between station %d and station %d is %I64d.\n",a,b,dist[a][b]);

74             }

75         }

76     }

77 }

 

你可能感兴趣的:(HDU)