#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <array>
#include <queue>
using namespace std;
typedef array<int, 3> Tab;
void print(const Tab& t) {
for (auto e : t) cerr << e << ' ';
cerr << endl;
}
int main() {
ios_base::sync_with_stdio(false);
int C, a, b, c;
array<int, 3> rozm;
vector<int> rozw;
int brakuje;
cin >> rozm[0] >> rozm[1] >> rozm[2] >> a >> b >> c;
C = rozm[2];
rozw.resize(C + 1, -1);
rozw[a] = rozw[b] = rozw[c] = 0;
brakuje = C + 1 - 3;
if (a == b) brakuje ++;
if (b == c) brakuje ++;
map<Tab, int> odw;
queue<Tab> kolej;
Tab elem = {a, b, c};
kolej.push(elem);
odw[elem] = 0;
while (!kolej.empty() && brakuje > 0) {
Tab t = kolej.front(); kolej.pop();
// cerr << odw[t] << ": ";
// print(t);
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (i == j) continue;
Tab tn = t;
tn[j] = min(t[i] + t[j], rozm[j]);
tn[i] = t[i] + t[j] - tn[j];
if (odw.find(tn) == odw.end()) {
int krok = odw[tn] = odw[t] + 1;
kolej.push(tn);
for (int k = 0; k < 3; k++) {
if (rozw[tn[k]] == -1) {
rozw[tn[k]] = krok;
brakuje --;
}
}
}
}
}
}
for (int i = 0; i <= C; i++) {
cout << rozw[i] << ' ';
}
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 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 | #include <vector> #include <iostream> #include <algorithm> #include <string> #include <map> #include <set> #include <array> #include <queue> using namespace std; typedef array<int, 3> Tab; void print(const Tab& t) { for (auto e : t) cerr << e << ' '; cerr << endl; } int main() { ios_base::sync_with_stdio(false); int C, a, b, c; array<int, 3> rozm; vector<int> rozw; int brakuje; cin >> rozm[0] >> rozm[1] >> rozm[2] >> a >> b >> c; C = rozm[2]; rozw.resize(C + 1, -1); rozw[a] = rozw[b] = rozw[c] = 0; brakuje = C + 1 - 3; if (a == b) brakuje ++; if (b == c) brakuje ++; map<Tab, int> odw; queue<Tab> kolej; Tab elem = {a, b, c}; kolej.push(elem); odw[elem] = 0; while (!kolej.empty() && brakuje > 0) { Tab t = kolej.front(); kolej.pop(); // cerr << odw[t] << ": "; // print(t); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (i == j) continue; Tab tn = t; tn[j] = min(t[i] + t[j], rozm[j]); tn[i] = t[i] + t[j] - tn[j]; if (odw.find(tn) == odw.end()) { int krok = odw[tn] = odw[t] + 1; kolej.push(tn); for (int k = 0; k < 3; k++) { if (rozw[tn[k]] == -1) { rozw[tn[k]] = krok; brakuje --; } } } } } } for (int i = 0; i <= C; i++) { cout << rozw[i] << ' '; } return 0; } |
English