#include <bits/stdc++.h> using namespace std; struct k { int a, b, c, t; }; int od[100001]; unordered_map <long long, int> czy; queue <k> q; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int pa, pb, pc, a, b, c; cin >> pa >> pb >> pc >> a >> b >> c; for(int i = 0; i <= pc; ++i) od[i] = INT_MAX; od[a] = 0; od[b] = 0; od[c] = 0; q.push({a, b, c, 0}); while(q.size()) { int ta = q.front().a; int tb = q.front().b; int tc = q.front().c; int tt = q.front().t; q.pop(); long long h = ((long long) ta<<34) + ((long long) tb<<17) + tc; if(czy[h]) continue; czy[h] = 1; od[ta] = min(od[ta], tt); od[tb] = min(od[tb], tt); od[tc] = min(od[tc], tt); q.push({ta-min(ta, pb-tb), tb+min(ta, pb-tb), tc, tt+1}); q.push({ta-min(ta, pc-tc), tb, tc+min(ta, pc-tc), tt+1}); q.push({ta+min(tb, pa-ta), tb-min(tb, pa-ta), tc, tt+1}); q.push({ta, tb-min(tb, pc-tc), tc+min(tb, pc-tc), tt+1}); q.push({ta+min(tc, pa-ta), tb, tc-min(tc, pa-ta), tt+1}); q.push({ta, tb+min(tc, pb-tb), tc-min(tc, pb-tb), tt+1}); } for(int i = 0; i <= pc; ++i) { if(od[i] != INT_MAX) cout << od[i] << " "; else cout << "-1 "; } return 0; }
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 | #include <bits/stdc++.h> using namespace std; struct k { int a, b, c, t; }; int od[100001]; unordered_map <long long, int> czy; queue <k> q; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int pa, pb, pc, a, b, c; cin >> pa >> pb >> pc >> a >> b >> c; for(int i = 0; i <= pc; ++i) od[i] = INT_MAX; od[a] = 0; od[b] = 0; od[c] = 0; q.push({a, b, c, 0}); while(q.size()) { int ta = q.front().a; int tb = q.front().b; int tc = q.front().c; int tt = q.front().t; q.pop(); long long h = ((long long) ta<<34) + ((long long) tb<<17) + tc; if(czy[h]) continue; czy[h] = 1; od[ta] = min(od[ta], tt); od[tb] = min(od[tb], tt); od[tc] = min(od[tc], tt); q.push({ta-min(ta, pb-tb), tb+min(ta, pb-tb), tc, tt+1}); q.push({ta-min(ta, pc-tc), tb, tc+min(ta, pc-tc), tt+1}); q.push({ta+min(tb, pa-ta), tb-min(tb, pa-ta), tc, tt+1}); q.push({ta, tb-min(tb, pc-tc), tc+min(tb, pc-tc), tt+1}); q.push({ta+min(tc, pa-ta), tb, tc-min(tc, pa-ta), tt+1}); q.push({ta, tb+min(tc, pb-tb), tc-min(tc, pb-tb), tt+1}); } for(int i = 0; i <= pc; ++i) { if(od[i] != INT_MAX) cout << od[i] << " "; else cout << "-1 "; } return 0; } |