#include <iostream> #include <functional> #include <vector> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int A, B, C, fa, fb, fc; cin >> A >> B >> C >> fa >> fb >> fc; vector<int> R(C + 1, INT32_MAX); auto assign = [&](int p, int x) { R[p] = min(R[p], x); }; function<void(int, int, int, int)> calc = [&](int a, int b, int c, int level) { assign(a, level), assign(b, level), assign(c, level); if (a == 0) { int turn = level, tb = b, tc = c; while (true) { if ((tb -= A) >= 0) assign(tb, ++turn); else break; if ((tc += A) <= C) assign(tc, ++turn); else break; } turn = level, tb = b, tc = c; while (true) { if ((tc -= A) >= 0) assign(tc, ++turn); else break; if ((tb += A) <= B) assign(tb, ++turn); else break; } } if (level++ == 10) return; if (a != 0 && b != B) calc(max(0, a + b - B), min(a + b, B), c, level); if (a != 0 && c != C) calc(max(0, a + c - C), b, min(a + c, C), level); if (b != 0 && a != A) calc(min(b + a, A), max(0, b + a - A), c, level); if (b != 0 && c != C) calc(a, max(0, b + c - C), min(b + c, C), level); if (c != 0 && a != A) calc(min(c + a, A), b, max(0, c + a - A), level); if (c != 0 && b != B) calc(a, min(c + b, B), max(0, c + b - B), level); }; calc(fa, fb, fc, 0); for (auto r : R) cout << (r == INT32_MAX ? -1 : r) << ' '; }
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 | #include <iostream> #include <functional> #include <vector> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int A, B, C, fa, fb, fc; cin >> A >> B >> C >> fa >> fb >> fc; vector<int> R(C + 1, INT32_MAX); auto assign = [&](int p, int x) { R[p] = min(R[p], x); }; function<void(int, int, int, int)> calc = [&](int a, int b, int c, int level) { assign(a, level), assign(b, level), assign(c, level); if (a == 0) { int turn = level, tb = b, tc = c; while (true) { if ((tb -= A) >= 0) assign(tb, ++turn); else break; if ((tc += A) <= C) assign(tc, ++turn); else break; } turn = level, tb = b, tc = c; while (true) { if ((tc -= A) >= 0) assign(tc, ++turn); else break; if ((tb += A) <= B) assign(tb, ++turn); else break; } } if (level++ == 10) return; if (a != 0 && b != B) calc(max(0, a + b - B), min(a + b, B), c, level); if (a != 0 && c != C) calc(max(0, a + c - C), b, min(a + c, C), level); if (b != 0 && a != A) calc(min(b + a, A), max(0, b + a - A), c, level); if (b != 0 && c != C) calc(a, max(0, b + c - C), min(b + c, C), level); if (c != 0 && a != A) calc(min(c + a, A), b, max(0, c + a - A), level); if (c != 0 && b != B) calc(a, min(c + b, B), max(0, c + b - B), level); }; calc(fa, fb, fc, 0); for (auto r : R) cout << (r == INT32_MAX ? -1 : r) << ' '; } |