#include <bits/stdc++.h> using namespace std; int A,B,C,a,b,c; int ile_ruch[100090]; void rek(int a_ter, int b_ter, int c_ter, int i_ruch){ if(i_ruch >= 8){ return; } ile_ruch[a_ter] = min(ile_ruch[a_ter], i_ruch); ile_ruch[b_ter] = min(ile_ruch[b_ter], i_ruch); ile_ruch[c_ter] = min(ile_ruch[c_ter], i_ruch); if(b_ter + a_ter <= B){ rek(0,b_ter+a_ter,c_ter,i_ruch +1); } else{ rek(a_ter - (B-b_ter), B,c_ter,i_ruch+1); } if(c_ter + a_ter <= C){ rek(0,b_ter,a_ter+c_ter,i_ruch +1); } else{ rek(a_ter - (C-c_ter), b_ter,C,i_ruch+1); } if(b_ter + a_ter <= A){ rek(b_ter+a_ter,0,c_ter,i_ruch +1); } else{ rek(A, b_ter - (A-a_ter),c_ter,i_ruch+1); } if(c_ter + a_ter <= A){ rek(c_ter + a_ter,b_ter,0,i_ruch +1); } else{ rek(A, b_ter,c_ter-(A-a_ter),i_ruch+1); } if(b_ter + c_ter <= B){ rek(a_ter,b_ter+c_ter,0,i_ruch +1); } else{ rek(a_ter, B,c_ter - (B-b_ter),i_ruch+1); } if(c_ter + b_ter <= C){ rek(a_ter,0,b_ter+c_ter,i_ruch +1); } else{ rek(a_ter, b_ter-(C-c_ter),C,i_ruch+1); } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> A >> B >> C; cin >> a >> b >> c; for (int x=0;x<=C;x++){ ile_ruch[x] = 100000; } rek(a,b,c,0); for (int x=0;x<=C;x++){ if (ile_ruch[x] ==100000){ cout << -1 << ' '; continue; } cout << ile_ruch[x] << ' '; } }
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 74 | #include <bits/stdc++.h> using namespace std; int A,B,C,a,b,c; int ile_ruch[100090]; void rek(int a_ter, int b_ter, int c_ter, int i_ruch){ if(i_ruch >= 8){ return; } ile_ruch[a_ter] = min(ile_ruch[a_ter], i_ruch); ile_ruch[b_ter] = min(ile_ruch[b_ter], i_ruch); ile_ruch[c_ter] = min(ile_ruch[c_ter], i_ruch); if(b_ter + a_ter <= B){ rek(0,b_ter+a_ter,c_ter,i_ruch +1); } else{ rek(a_ter - (B-b_ter), B,c_ter,i_ruch+1); } if(c_ter + a_ter <= C){ rek(0,b_ter,a_ter+c_ter,i_ruch +1); } else{ rek(a_ter - (C-c_ter), b_ter,C,i_ruch+1); } if(b_ter + a_ter <= A){ rek(b_ter+a_ter,0,c_ter,i_ruch +1); } else{ rek(A, b_ter - (A-a_ter),c_ter,i_ruch+1); } if(c_ter + a_ter <= A){ rek(c_ter + a_ter,b_ter,0,i_ruch +1); } else{ rek(A, b_ter,c_ter-(A-a_ter),i_ruch+1); } if(b_ter + c_ter <= B){ rek(a_ter,b_ter+c_ter,0,i_ruch +1); } else{ rek(a_ter, B,c_ter - (B-b_ter),i_ruch+1); } if(c_ter + b_ter <= C){ rek(a_ter,0,b_ter+c_ter,i_ruch +1); } else{ rek(a_ter, b_ter-(C-c_ter),C,i_ruch+1); } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> A >> B >> C; cin >> a >> b >> c; for (int x=0;x<=C;x++){ ile_ruch[x] = 100000; } rek(a,b,c,0); for (int x=0;x<=C;x++){ if (ile_ruch[x] ==100000){ cout << -1 << ' '; continue; } cout << ile_ruch[x] << ' '; } } |