#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define st first #define nd second #define pb push_back #define rep(i,a,b) for(ll i=a;i<=b;i++) #define all(a) a.begin(),a.end() const int mxN = 1e5+7; const int INF = 1e9+7; int odp[mxN]; int A[10]; pair<int,int> r[6] = {{0,1},{0,2},{1,0},{1,2},{2,0},{2,1}}; void rek(vector<int> v,pair<int,int> m,int nr,int gl){ if(gl > 10) return; int z = m.st, d = m.nd; if(v[z] > A[d]-v[d]){ v[z] -= (A[d]-v[d]); v[d] = A[d]; }else{ v[d] += v[z]; v[z] = 0; } odp[v[d]] = min(odp[v[d]],gl); odp[v[z]] = min(odp[v[z]],gl); rep(i,0,5) if(i != nr) rek(v,r[i],i,gl+1); } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int a,b,c; cin >> A[0] >> A[1] >> A[2]; cin >> a >> b >> c; rep(i,0,A[2]) odp[i] = INF; odp[a] = 0; odp[b] = 0; odp[c] = 0; vector<int> v; v.pb(a); v.pb(b); v.pb(c); v.pb(0); v.pb(0); rep(i,0,5) rek(v,r[i],i,1); rep(i,0,A[2]) cout << ((odp[i] == INF) ? -1 : odp[i]) << " "; cout << "\n"; }
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 | #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define st first #define nd second #define pb push_back #define rep(i,a,b) for(ll i=a;i<=b;i++) #define all(a) a.begin(),a.end() const int mxN = 1e5+7; const int INF = 1e9+7; int odp[mxN]; int A[10]; pair<int,int> r[6] = {{0,1},{0,2},{1,0},{1,2},{2,0},{2,1}}; void rek(vector<int> v,pair<int,int> m,int nr,int gl){ if(gl > 10) return; int z = m.st, d = m.nd; if(v[z] > A[d]-v[d]){ v[z] -= (A[d]-v[d]); v[d] = A[d]; }else{ v[d] += v[z]; v[z] = 0; } odp[v[d]] = min(odp[v[d]],gl); odp[v[z]] = min(odp[v[z]],gl); rep(i,0,5) if(i != nr) rek(v,r[i],i,gl+1); } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int a,b,c; cin >> A[0] >> A[1] >> A[2]; cin >> a >> b >> c; rep(i,0,A[2]) odp[i] = INF; odp[a] = 0; odp[b] = 0; odp[c] = 0; vector<int> v; v.pb(a); v.pb(b); v.pb(c); v.pb(0); v.pb(0); rep(i,0,5) rek(v,r[i],i,1); rep(i,0,A[2]) cout << ((odp[i] == INF) ? -1 : odp[i]) << " "; cout << "\n"; } |