#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int przelej(int x, int wx, int y, int wy)
{
return min(x, wy - y);
}
int main()
{
ios_base::sync_with_stdio(false);
int but[3][2];
int suma = 0;
for(int i=0; i < 3; i++)
{
cin >> but[i][0];
}
for(int i=0; i < 3; i++)
{
cin >> but[i][1];
suma += but[i][1];
}
vector<int> pojemnosc(but[2][0]+1, -1);
map<pair<int, int>, int> mapa;
queue<pair<int, int>> q;
q.push({but[0][1], but[1][1]});
mapa[{but[0][1], but[1][1]}] = 0;
while(!q.empty())
{
auto [x, y] = q.front();
q.pop();
int z = suma - x - y;
but[0][1] = x;
but[1][1] = y;
but[2][1] = z;
int ile = mapa[{x, y}];
if (pojemnosc[x] == -1) {
pojemnosc[x] = ile;
}
if (pojemnosc[y] == -1) {
pojemnosc[y] = ile;
}
if (pojemnosc[z] == -1) {
pojemnosc[z] = ile;
}
for (int i=0; i < 3; i++)
{
for (int j=0; j < 3; j++) {
if (i == j) {
continue;
}
int w = min(but[i][1], but[j][0] - but[j][1]);
but[i][1] -= w;
but[j][1] += w;
pair<int, int> p = {but[0][1], but[1][1]};
if (mapa.find(p) == mapa.end())
{
mapa[p] = ile+1;
q.push(p);
}
but[i][1] += w;
but[j][1] -= w;
}
}
}
for (int i=0; i <= but[2][0]; i++)
{
cout << pojemnosc[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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | #include <bits/stdc++.h> #include <iostream> using namespace std; int przelej(int x, int wx, int y, int wy) { return min(x, wy - y); } int main() { ios_base::sync_with_stdio(false); int but[3][2]; int suma = 0; for(int i=0; i < 3; i++) { cin >> but[i][0]; } for(int i=0; i < 3; i++) { cin >> but[i][1]; suma += but[i][1]; } vector<int> pojemnosc(but[2][0]+1, -1); map<pair<int, int>, int> mapa; queue<pair<int, int>> q; q.push({but[0][1], but[1][1]}); mapa[{but[0][1], but[1][1]}] = 0; while(!q.empty()) { auto [x, y] = q.front(); q.pop(); int z = suma - x - y; but[0][1] = x; but[1][1] = y; but[2][1] = z; int ile = mapa[{x, y}]; if (pojemnosc[x] == -1) { pojemnosc[x] = ile; } if (pojemnosc[y] == -1) { pojemnosc[y] = ile; } if (pojemnosc[z] == -1) { pojemnosc[z] = ile; } for (int i=0; i < 3; i++) { for (int j=0; j < 3; j++) { if (i == j) { continue; } int w = min(but[i][1], but[j][0] - but[j][1]); but[i][1] -= w; but[j][1] += w; pair<int, int> p = {but[0][1], but[1][1]}; if (mapa.find(p) == mapa.end()) { mapa[p] = ile+1; q.push(p); } but[i][1] += w; but[j][1] -= w; } } } for (int i=0; i <= but[2][0]; i++) { cout << pojemnosc[i] << " "; } } |
English