-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathp2251.java
More file actions
65 lines (56 loc) · 1.85 KB
/
p2251.java
File metadata and controls
65 lines (56 loc) · 1.85 KB
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
import java.util.*;
import java.io.*;
public class p2251 {
static BufferedReader br;
static StringTokenizer st;
public static void main(String[] args) throws IOException {
br = new BufferedReader(new InputStreamReader(System.in));
int [] a = new int[3];
st = new StringTokenizer(br.readLine());
for(int i=0; i<3; i++) {
a[i] = Integer.parseInt(st.nextToken());
}
int [] from = {0, 0, 1, 1, 2, 2};
int [] to = {1, 2, 0, 2, 0, 1};
boolean [][]check = new boolean[201][201];
boolean [] ans = new boolean[201];
Queue<Pair> q = new LinkedList<>();
q.add(new Pair(0, 0));
check[0][0] = true;
ans[a[2]] = true;
while (!q.isEmpty()) {
Pair p = q.poll();
int x = p.x;
int y = p.y;
int z = a[2]-x-y;
for (int k=0; k<6; k++) {
int [] next = {x, y, z};
next[to[k]] += next[from[k]];
next[from[k]] = 0;
if (next[to[k]] > a[to[k]]) { //물통의 용량보다 물이 많을 때
next[from[k]] = next[to[k]] - a[to[k]]; //초과하는 만큼 다시 넣어주고
next[to[k]] = a[to[k]]; //용량에 가득 찬 물을 넣어준다.
}
if (!check[next[0]][next[1]]) {
check[next[0]][next[1]] = true;
q.add(new Pair(next[0], next[1]));
if (next[0] == 0) {
ans[next[2]] = true;
}
}
}
}
for (int i=0; i<=a[2]; i++) {
if (ans[i])
System.out.print(i+ " ");
}
}
}
class Pair {
int x;
int y;
public Pair (int x, int y) {
this.x = x;
this.y = y;
}
}