我是靠谱客的博主 昏睡小土豆,这篇文章主要介绍hdu 1690(简洁版),现在分享给大家,希望可以做个参考。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include <iostream> #include <stdio.h> #include <queue> #include <string.h> using namespace std; #define inf 10000000000000 __int64 map[101][101]; __int64 d[101]; bool hash[101]; __int64 a[101]; __int64 l1,l2,l3,l4,c1,c2,c3,c4; __int64 n,m; __int64 start,end; struct node{ __int64 adj; __int64 weight; node* next; }node,*pnode; struct Heap{ bool operator<(Heap T)const{ return T.dis < dis; } __int64 x; __int64 dis; }; priority_queue<Heap> Q; __int64 bfs(){ __int64 i; for(i = 0 ; i <= 100 ; ++i){ hash[i] = 0; d[i] = inf; } Heap min,in; while(!Q.empty()){ Q.pop(); } in.x = start; in.dis = 0; d[start] = 0; Q.push(in); while(!Q.empty()){ min = Q.top(); Q.pop(); if(min.x == end){ return min.dis; } if(hash[min.x]){ continue; } hash[min.x] = true; for(i = 1 ; i <= n ; ++i){ if(d[i] > d[min.x] + map[min.x][i] && !hash[i]){ in.x = i; in.dis = map[min.x][i] + d[min.x]; d[i] = in.dis; Q.push(in); } } } return -1; } int judge(int dis){ if(dis > 0 && dis <= l1){ return c1; }else{ if(dis >l1 && dis <= l2){ return c2; }else{ if(dis > l2 && dis <=l3){ return c3; }else if(dis > l3 && dis <= l4){ return c4; }else{ return -1; } } } } int main(){ int t; scanf("%d",&t); int p = 1; while(t--){ scanf("%I64d%I64d%I64d%I64d%I64d%I64d%I64d%I64d",&l1,&l2,&l3,&l4,&c1,&c2,&c3,&c4); scanf("%I64d%I64d",&n,&m); __int64 i,j; for(i = 1 ; i <= n ; ++i){ for(j = 1 ; j <= n ; ++j){ map[i][j] = inf; } } for(i = 1 ; i <=n ; ++i){ scanf("%I64d",&a[i]); } for(i = 1 ; i <= n ; ++i){ for(j = 1 ; j <= n ; ++j){ // a[i] - a[j] :计算站于占志坚的距离 __int64 l = a[i] - a[j]; if( l < 0){ l = -l; } //judge(l) :计算这个距离所对应的费用 __int64 s = judge(l); if(s < 0){ s = inf; } map[i][j] = s; map[j][i] = s; } } printf("Case %d:n",p++); for(i = 1 ; i <= m ; ++i){ scanf("%I64d%I64d",&start,&end); bfs(); if(d[end] == inf){ printf("Station %I64d and station %I64d are not attainable.n",start,end); }else{ printf("The minimum cost between station %I64d and station %I64d is %I64d.n",start,end,d[end]); } } } }

最后

以上就是昏睡小土豆最近收集整理的关于hdu 1690(简洁版)的全部内容,更多相关hdu内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(57)

评论列表共有 0 条评论

立即
投稿
返回
顶部