#include <bits/stdc++.h> #define dbg(x) " [" << #x << ": " << (x) << "] " using namespace std; template<typename A,typename B> ostream& operator<<(ostream& out,const pair<A,B>& p) { return out << "(" << p.first << ", " << p.second << ")"; } template<typename T> ostream& operator<<(ostream& out,const vector<T>& c) { out << "{"; for(auto it = c.begin(); it != c.end(); it++) { if(it != c.begin()) out << ", "; out << *it; } return out << "}"; } void solve() { int a,b,c; vector<int> s(3); map<vector<int>,int> u; cin >> s[0] >> s[1] >> s[2] >> a >> b >> c; queue<vector<int>> q; vector<int> vvv = {a,b,c}; q.push(vvv); u[vvv] = 1; vector<int> ans(s[2] + 1,1e9); while(!q.empty()) { vector<int> v = q.front(); q.pop(); int d = u[v] - 1; for(int i = 0; i < 3; i++) { ans[v[i]] = min(ans[v[i]],d); for(int j = 0; j < 3; j++) { if(i == j) continue; vector<int> vv = v; int x = min(v[i],s[j] - v[j]); vv[i] -= x; vv[j] += x; if(!u[vv]) { u[vv] = u[v] + 1; q.push(vv); } } } } for(int i = 0; i < ans.size(); i++) { if(ans[i] == 1e9) ans[i] = -1; cout << ans[i] << " "; } cout << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int testNum = 1; //cin >> testNum; for(int i = 1; i <= testNum; i++) { solve(); } 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 60 61 62 63 | #include <bits/stdc++.h> #define dbg(x) " [" << #x << ": " << (x) << "] " using namespace std; template<typename A,typename B> ostream& operator<<(ostream& out,const pair<A,B>& p) { return out << "(" << p.first << ", " << p.second << ")"; } template<typename T> ostream& operator<<(ostream& out,const vector<T>& c) { out << "{"; for(auto it = c.begin(); it != c.end(); it++) { if(it != c.begin()) out << ", "; out << *it; } return out << "}"; } void solve() { int a,b,c; vector<int> s(3); map<vector<int>,int> u; cin >> s[0] >> s[1] >> s[2] >> a >> b >> c; queue<vector<int>> q; vector<int> vvv = {a,b,c}; q.push(vvv); u[vvv] = 1; vector<int> ans(s[2] + 1,1e9); while(!q.empty()) { vector<int> v = q.front(); q.pop(); int d = u[v] - 1; for(int i = 0; i < 3; i++) { ans[v[i]] = min(ans[v[i]],d); for(int j = 0; j < 3; j++) { if(i == j) continue; vector<int> vv = v; int x = min(v[i],s[j] - v[j]); vv[i] -= x; vv[j] += x; if(!u[vv]) { u[vv] = u[v] + 1; q.push(vv); } } } } for(int i = 0; i < ans.size(); i++) { if(ans[i] == 1e9) ans[i] = -1; cout << ans[i] << " "; } cout << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int testNum = 1; //cin >> testNum; for(int i = 1; i <= testNum; i++) { solve(); } return 0; } |