[๋ฐฑ์ค€-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ํ•ด์ค€๋‹ค.