#include <bits/stdc++.h>
using namespace std;
constexpr int LIM = 1e5;
int t[3], v[3], res[LIM + 3];
const int mxLvl = 5;
const int INF = 1e9 + 3;
void fun(int vals[3], int cnt) {
if(cnt > mxLvl) {
return;
}
for(int i = 0; i < 3; ++i) {
res[vals[i]] = min(res[vals[i]], cnt);
}
for(int i = 0; i < 3; ++i) {
if(vals[i]) {
for(int j = 0; j < 3; ++j) {
if(j != i && vals[j] != t[j]) {
int tmp[3] = {vals[0], vals[1], vals[2]};
tmp[j] = min(t[j], vals[j] + vals[i]);
tmp[i] = vals[i] - min(t[j] - vals[j], vals[i]);
fun(tmp, cnt + 1);
}
}
}
}
}
int main() {
for(int i = 0; i < 3; ++i) {
scanf("%d", &t[i]);
}
for(int i = 0; i < 3; ++i) {
scanf("%d", &v[i]);
}
for(int i = 0; i <= t[2]; ++i) {
res[i] = INF;
}
fun(v, 0);
for(int i = 0; i <= t[2]; ++i) {
printf("%d ", res[i] == INF ? -1 : res[i]);
}
}
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 | #include <bits/stdc++.h> using namespace std; constexpr int LIM = 1e5; int t[3], v[3], res[LIM + 3]; const int mxLvl = 5; const int INF = 1e9 + 3; void fun(int vals[3], int cnt) { if(cnt > mxLvl) { return; } for(int i = 0; i < 3; ++i) { res[vals[i]] = min(res[vals[i]], cnt); } for(int i = 0; i < 3; ++i) { if(vals[i]) { for(int j = 0; j < 3; ++j) { if(j != i && vals[j] != t[j]) { int tmp[3] = {vals[0], vals[1], vals[2]}; tmp[j] = min(t[j], vals[j] + vals[i]); tmp[i] = vals[i] - min(t[j] - vals[j], vals[i]); fun(tmp, cnt + 1); } } } } } int main() { for(int i = 0; i < 3; ++i) { scanf("%d", &t[i]); } for(int i = 0; i < 3; ++i) { scanf("%d", &v[i]); } for(int i = 0; i <= t[2]; ++i) { res[i] = INF; } fun(v, 0); for(int i = 0; i <= t[2]; ++i) { printf("%d ", res[i] == INF ? -1 : res[i]); } } |
English