USACO Mother's Milk

Code

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
/*
ID: wcr19961
PROG: milk3
LANG: C++11
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <queue>
using namespace std;
const int maxn = 25;
const int F[] = {0, 0, 1, 1, 2, 2};
const int T[] = {1, 2, 0, 2, 0, 1};
int a[3];
bool vis[maxn][maxn][maxn];
struct Node {
int a[3];
Node(int x, int y, int z) {
a[0] = x, a[1] = y, a[2] = z;
}
};
queue<Node> q;
void pour(int f, int t, Node k) {
if (k.a[f] > 0 && k.a[t] < a[t]) {
int dt = min(k.a[f], a[t] - k.a[t]);
k.a[f] -= dt, k.a[t] += dt;
if (!vis[k.a[0]][k.a[1]][k.a[2]]) {
q.push(k);
vis[k.a[0]][k.a[1]][k.a[2]] = true;
}
}
}
int main() {
freopen("milk3.in", "r", stdin);
freopen("milk3.out", "w", stdout);
scanf("%d%d%d", &a[0], &a[1], &a[2]);
q.push(Node(0, 0, a[2]));
vis[0][0][a[2]] = true;
while (!q.empty()) {
Node k = q.front();
q.pop();
for (int i = 0; i < 6; ++i) {
pour(F[i], T[i], k);
}
}
bool flag = true;
for (int i = 0; i <= a[2]; ++i) {
if (vis[0][a[2] - i][i]) {
if (flag) {
flag = false;
} else {
putchar(' ');
}
printf("%d", i);
}
}
puts("");
return 0;
}