티스토리 뷰
728x90
https://www.acmicpc.net/problem/2251
2251번: 물통
각각 부피가 A, B, C(1≤A, B, C≤200) 리터인 세 개의 물통이 있다. 처음에는 앞의 두 물통은 비어 있고, 세 번째 물통은 가득(C 리터) 차 있다. 이제 어떤 물통에 들어있는 물을 다른 물통으로 쏟아 부
www.acmicpc.net
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
|
from collections import deque
def chk(x, y):
if not visit[x][y]:
visit[x][y] = True
dq.append((x, y))
def bfs():
while dq:
x, y = dq.popleft()
z = c - x - y
if x == 0:
answer.append(z)
# x -> y
water = min(x, b - y)
chk(x - water, y + water)
# x -> z
water = min(x, c - z)
chk(x - water, y)
# y -> x
water = min(y, a - x)
chk(x + water, y - water)
# y -> z
water = min(y, c - z)
chk(x, y - water)
# z -> x
water = min(z, a - x)
chk(x + water, y)
# z -> y
water = min(z, b - y)
chk(x, y + water)
a, b, c = map(int, input().split())
visit = [[False for _ in range(201)] for _ in range(201)]
visit[0][0] = True
dq = deque()
dq.append((0, 0))
answer = []
bfs()
answer.sort()
print(' '.join(map(str, answer)))
|
cs |
'코딩 > 파이썬 백준' 카테고리의 다른 글
백준 2583 영역 구하기 (파이썬) (0) | 2022.03.07 |
---|---|
백준 2667 단지번호붙이기 (파이썬) (0) | 2022.03.07 |
백준 2304 창고 다각형 (파이썬) (0) | 2022.03.02 |
백준 16396 선 그리기 (파이썬) (0) | 2022.03.01 |
백준 7571 점 모으기 (파이썬) (0) | 2022.02.17 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 백준 12788
- 백준 13335 파이썬
- 백준 2304 파이썬
- 백준 23253 파이썬
- 백준 10825 파이썬
- 백준 12034
- 백준 20362
- 백준 1351
- 백준 2075 파이썬
- 백준 2075
- 백준 10825
- 백준 2491 파이썬
- 백준 4446 파이썬
- 백준 6593 파이썬
- 백준 13335
- 백준 1916
- 백준 11123 파이썬
- 백준 12788 파이썬
- 백준 1351 파이썬
- 백준 9205 파이썬
- 백준 1504 파이썬
- 백준 9205
- 백준 1916 파이썬
- 백준 4446
- 백준 2304
- 백준 6593
- 백준 12034 파이썬
- 백준 23253
- 백준 20362 파이썬
- 백준 11123
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함