diff --git "a/pknujsp/BRUTE_FORCE/38-\354\236\220\353\254\274\354\207\240\354\231\200 \354\227\264\354\207\240.py" "b/pknujsp/BRUTE_FORCE/38-\354\236\220\353\254\274\354\207\240\354\231\200 \354\227\264\354\207\240.py" new file mode 100644 index 00000000..e1cc927a --- /dev/null +++ "b/pknujsp/BRUTE_FORCE/38-\354\236\220\353\254\274\354\207\240\354\231\200 \354\227\264\354\207\240.py" @@ -0,0 +1,50 @@ +# 자물쇠의 중간 부분이 모두 1인지 확인 +def is_valid(new_lock): + length = len(new_lock) // 3 + + for r in range(length, length * 2): + for c in range(length, length * 2): + if new_lock[r][c] != 1: + return False + + return True + +def solution(key, lock): + n = len(lock) + k = len(key) + new_lock = [[0] * (n * 3) for _ in range(n * 3)] + + for r in range(n): + for c in range(n): + new_lock[r + n][c + n] = lock[r][c] + + for _ in range(4): + rev_key = key[::-1] + key = [] + for c in range(k): + row = [] + for r in range(k): + row.append(rev_key[r][c]) + key.append(row) + + """ + 열쇠를 돌리는 로직은 한 줄로도 구현가능 합니다 + key = [row for row in zip(*reversed(key))] + """ + + for r in range(n * 2): + for c in range(n * 2): + # 자물쇠에 열쇠를 끼운다 + for i in range(k): + for j in range(k): + new_lock[r + i][c + j] += key[i][j] + + # 자물쇠에 열쇠가 딱 들어갔는지 확인 + if is_valid(new_lock): + return True + + # 자물쇠에서 열쇠를 빼서 복구시킨다 + for i in range(k): + for j in range(k): + new_lock[r + i][c + j] -= key[i][j] + return False \ No newline at end of file diff --git a/pknujsp/README.md b/pknujsp/README.md index 571b70d7..6859f496 100644 --- a/pknujsp/README.md +++ b/pknujsp/README.md @@ -38,4 +38,5 @@ | 34차시 | 2024.02.12 | BFS | [이분 그래프](https://www.acmicpc.net/problem/1707) | [#135](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/135) | | 35차시 | 2024.02.18 | 그리디 | [선물할인](https://www.acmicpc.net/problem/25947) | [#137](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/137) | | 36차시 | 2024.02.21 | 이진탐색 | [휴게소 세우기](https://www.acmicpc.net/problem/1477) | [#143](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/143) | -| 37차시 | 2024.03.04 | 구현 | [n+1 카드게임](https://school.programmers.co.kr/learn/courses/30/lessons/258707) | [#149](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/149) | \ No newline at end of file +| 37차시 | 2024.03.04 | 구현 | [n+1 카드게임](https://school.programmers.co.kr/learn/courses/30/lessons/258707) | [#149](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/149) | +| 38차시 | 2024.03.08 | BRUTE_FORCE | [자물쇠와 열쇠](https://school.programmers.co.kr/learn/courses/30/lessons/60059) | [#154](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/154) | \ No newline at end of file