From deffa7eab8749519f0562c260add31bf7bab929a Mon Sep 17 00:00:00 2001 From: tgyuu-An Date: Fri, 7 Jun 2024 18:29:36 +0900 Subject: [PATCH] 2024-06-07 --- tgyuuAn/README.md | 1 + .../\353\266\210 \353\201\204\352\270\260.py" | 40 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 "tgyuuAn/\352\267\270\353\246\254\353\224\224/\353\266\210 \353\201\204\352\270\260.py" diff --git a/tgyuuAn/README.md b/tgyuuAn/README.md index 093a7e46..edc59892 100644 --- a/tgyuuAn/README.md +++ b/tgyuuAn/README.md @@ -63,4 +63,5 @@ | 56차시 | 2023.05.18 | BFS | 공주님을 구해라! | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/193 | 57차시 | 2023.05.26 | 분할 정복 | 트리의 순회 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/197 | 58차시 | 2023.05.30 | 백트래킹 | 비숍 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/204 +| 60차시 | 2023.06.07 | 그리디 | 불 끄기 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/209 --- diff --git "a/tgyuuAn/\352\267\270\353\246\254\353\224\224/\353\266\210 \353\201\204\352\270\260.py" "b/tgyuuAn/\352\267\270\353\246\254\353\224\224/\353\266\210 \353\201\204\352\270\260.py" new file mode 100644 index 00000000..8a96169c --- /dev/null +++ "b/tgyuuAn/\352\267\270\353\246\254\353\224\224/\353\266\210 \353\201\204\352\270\260.py" @@ -0,0 +1,40 @@ +from itertools import product +from copy import deepcopy +import sys + +N = 10 +INF = int(1e9) +board = [list(input()) for _ in range(N)] +answer = INF + +def push(board, y, x): + dx = [0, 0, 0, -1, 1] + dy = [0, -1, 1, 0, 0] + + for dir in range(5): + new_y = y + dy[dir] + new_x = x + dx[dir] + + if new_y < 0 or new_y >= N: continue + if new_x < 0 or new_x >= N: continue + + board[new_y][new_x] = "O" if board[new_y][new_x] == "#" else "#" + +for first_row_pushed in product(range(2), repeat = N): + new_board = deepcopy(board) + count = 0 + + for idx, pushed in enumerate(first_row_pushed): + if pushed == True: + count += 1 + push(new_board, 0, idx) + + for y in range(1, N): + for x in range(N): + if new_board[y-1][x] == "O": + count += 1 + push(new_board, y, x) + + if all(element == "#" for element in new_board[-1]): answer = min(answer, count) + +print(answer if answer != INF else -1) \ No newline at end of file