#include <bits/stdc++.h> using namespace std; #define pii pair<int, int> #define vv vector<int> const int MAXN = 1e5+1; const int INF = 1e9; map<vv, int> mp; int mx[3], b[3], ans[MAXN]; void bfs() { queue<vv> q; vv v{b[0], b[1], b[2]}; q.push(v); mp[v] = 0; for (int i=0; i<3; ++i) { ans[b[i]] = 0; } while (!q.empty()) { vv x = q.front(); q.pop(); for (int i=0; i<3; ++i) { for (int j=0; j<3; ++j) { if (i == j) continue; vv c = x; if (x[i]+x[j] <= mx[j]) { c[j] = x[i]+x[j]; c[i] = 0; } else { c[i] = c[i]-mx[j]+x[j]; c[j] = mx[j]; } if (mp.find(c) == mp.end()) { mp[c] = mp[x]+1; q.push(c); for (int i=0; i<3; ++i) { ans[c[i]] = min(ans[c[i]], mp[c]); } } } } } } int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); for (int i=0; i<3; ++i) cin>>mx[i]; for (int i=0; i<3; ++i) cin>>b[i]; for (int i=0; i<MAXN; ++i) { ans[i] = INF; } bfs(); for (int i=0; i<=mx[2]; ++i) { if (ans[i] == INF) cout<<-1<<" "; else cout<<ans[i]<<" "; } cout<<endl; }
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 | #include <bits/stdc++.h> using namespace std; #define pii pair<int, int> #define vv vector<int> const int MAXN = 1e5+1; const int INF = 1e9; map<vv, int> mp; int mx[3], b[3], ans[MAXN]; void bfs() { queue<vv> q; vv v{b[0], b[1], b[2]}; q.push(v); mp[v] = 0; for (int i=0; i<3; ++i) { ans[b[i]] = 0; } while (!q.empty()) { vv x = q.front(); q.pop(); for (int i=0; i<3; ++i) { for (int j=0; j<3; ++j) { if (i == j) continue; vv c = x; if (x[i]+x[j] <= mx[j]) { c[j] = x[i]+x[j]; c[i] = 0; } else { c[i] = c[i]-mx[j]+x[j]; c[j] = mx[j]; } if (mp.find(c) == mp.end()) { mp[c] = mp[x]+1; q.push(c); for (int i=0; i<3; ++i) { ans[c[i]] = min(ans[c[i]], mp[c]); } } } } } } int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); for (int i=0; i<3; ++i) cin>>mx[i]; for (int i=0; i<3; ++i) cin>>b[i]; for (int i=0; i<MAXN; ++i) { ans[i] = INF; } bfs(); for (int i=0; i<=mx[2]; ++i) { if (ans[i] == INF) cout<<-1<<" "; else cout<<ans[i]<<" "; } cout<<endl; } |