#include <cstdio> #include <set> int A, B, C, s, n = 0, r = 0; int R[100001]; std::set <std::pair <int, int>> Q, V; void ins (int a, int b) { if (!V.emplace (a, b).second) return; Q.emplace (a, b); if (R[a] == -1) R[a] = n, r++; if (R[b] == -1) R[b] = n, r++; if (R[s-a-b] == -1) R[s-a-b] = n, r++; } int main () { int a, b, c, q; scanf ("%i%i%i%i%i%i", &A, &B, &C, &a, &b, &c); s = a + b + c; for (int i=0; i<=C; i++) R[i] = -1; ins (a, b); while (r<=C && Q.size ()>0) { n++; auto P = Q; Q.clear (); for (auto i: P) { a = i.first, b = i.second, c = s-a-b; if (a && b<B) q = std::min (a, B-b), ins (a-q, b+q); if (a && c<C) q = std::min (a, C-c), ins (a-q, b); if (b && a<A) q = std::min (b, A-a), ins (a+q, b-q); if (b && c<C) q = std::min (b, C-c), ins (a, b-q); if (c && a<A) q = std::min (c, A-a), ins (a+q, b); if (c && b<B) q = std::min (c, B-b), ins (a, b+q); } } for (int i=0; i<=C; i++) printf ("%i%c", R[i], " \n"[i==C]); 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 | #include <cstdio> #include <set> int A, B, C, s, n = 0, r = 0; int R[100001]; std::set <std::pair <int, int>> Q, V; void ins (int a, int b) { if (!V.emplace (a, b).second) return; Q.emplace (a, b); if (R[a] == -1) R[a] = n, r++; if (R[b] == -1) R[b] = n, r++; if (R[s-a-b] == -1) R[s-a-b] = n, r++; } int main () { int a, b, c, q; scanf ("%i%i%i%i%i%i", &A, &B, &C, &a, &b, &c); s = a + b + c; for (int i=0; i<=C; i++) R[i] = -1; ins (a, b); while (r<=C && Q.size ()>0) { n++; auto P = Q; Q.clear (); for (auto i: P) { a = i.first, b = i.second, c = s-a-b; if (a && b<B) q = std::min (a, B-b), ins (a-q, b+q); if (a && c<C) q = std::min (a, C-c), ins (a-q, b); if (b && a<A) q = std::min (b, A-a), ins (a+q, b-q); if (b && c<C) q = std::min (b, C-c), ins (a, b-q); if (c && a<A) q = std::min (c, A-a), ins (a+q, b); if (c && b<B) q = std::min (c, B-b), ins (a, b+q); } } for (int i=0; i<=C; i++) printf ("%i%c", R[i], " \n"[i==C]); return 0; } |