[๋ฐฑ์ค-2251] ๋ฌผํต / Python
๐ Problem Solving/Baekjoon
2251๋ฒ: ๋ฌผํต
๊ฐ๊ฐ ๋ถํผ๊ฐ A, B, C(1≤A, B, C≤200) ๋ฆฌํฐ์ธ ์ธ ๊ฐ์ ๋ฌผํต์ด ์๋ค. ์ฒ์์๋ ์์ ๋ ๋ฌผํต์ ๋น์ด ์๊ณ , ์ธ ๋ฒ์งธ ๋ฌผํต์ ๊ฐ๋(C ๋ฆฌํฐ) ์ฐจ ์๋ค. ์ด์ ์ด๋ค ๋ฌผํต์ ๋ค์ด์๋ ๋ฌผ์ ๋ค๋ฅธ ๋ฌผํต์ผ๋ก ์์ ๋ถ
www.acmicpc.net
import sys
from collections import deque
input = sys.stdin.readline
def bfs():
while queue:
x, y, z = queue.popleft()
if check[x][y] == 1:
continue
check[x][y] = 1
if x == 0:
answer[z] = 1
if x + y > b:
queue.append([x + y - b, b, z])
else:
queue.append([0, x + y, z])
if x + z > c:
queue.append([x + z - c, y, c])
else:
queue.append([0, y, x + z])
if y + x > a:
queue.append([a, y + x - a, z])
else:
queue.append([y + x, 0, z])
if y + z > c:
queue.append([x, y + z - c, c])
else:
queue.append([x, 0, y + z])
if z + x > a:
queue.append([a, y, z + x - a])
else:
queue.append([z + x, y, 0])
if z + y > b:
queue.append([x, b, z + y - b])
a, b, c = map(int, input().split())
check = [[0] * 201 for _ in range(201)]
answer = [0] * 201
queue = deque()
queue.append((0, 0, c))
bfs()
for i in range(201):
if answer[i]:
print(i, end=" ")
ํด์ค
a -> b
a -> c
b -> a
b -> c
c -> a
c -> b
6๊ฐ์ง ๊ฒฝ์ฐ์ ์๋ฅผ ๊ณ์ฐํด์ฃผ๋ฉด์ bfsํด์ค๋ค.
'๐ Problem Solving > Baekjoon' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค-1743] ์์๋ฌผ ํผํ๊ธฐ / Python (0) | 2021.07.02 |
---|---|
[๋ฐฑ์ค-1926] ๊ทธ๋ฆผ / Python (0) | 2021.07.01 |
[๋ฐฑ์ค-17413] ๋จ์ด ๋ค์ง๊ธฐ 2 / Python (1) | 2021.06.28 |
[๋ฐฑ์ค-1138] ํ ์ค๋ก ์๊ธฐ / Python (0) | 2021.06.21 |
[๋ฐฑ์ค-1051] ์ซ์ ์ ์ฌ๊ฐํ / Python (0) | 2021.06.21 |