Link : programmers.co.kr/learn/courses/30/lessons/60059
Python
더보기
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
|
import copy
def rotation(shape):
'''
:param location: (위치 좌표)
:return: 시계방향 90도 회전
'''
n = len(shape)
m = len(shape[0])
result = [[0] * n for _ in range(m)]
for i in range(n):
for j in range(m):
result[j][n - i - 1] = shape[i][j]
return result
def check(board, K, L):
for y in range(L):
for x in range(L):
if board[y + K][x + K] != 1:
return False
return True
def solution(key, lock):
K, L = len(key), len(lock)
board_map = [[0 for _ in range(K * 2 + L)] for _ in range(K * 2 + L)]
for i in range(L):
for j in range(L):
board_map[i + K][j + K] = lock[i][j]
for _ in range(4):
for y in range(1, K + L):
for x in range(1, K + L):
t_board = copy.deepcopy(board_map)
for j in range(K):
for i in range(K):
t_board[j + y][i + x] += key[j][i]
if check(t_board, K, L):
return True
key = rotation(key)
return False
|
cs |
FeedBack
- rotation 함수를 list(zip(*shape[::-1]))로 대체 가능함.
cjw.git@gmail.com
'알고리즘 > 소스코드' 카테고리의 다른 글
ALGOSPOT BOARDCOVER: 게임판 덮기 (0) | 2021.02.20 |
---|---|
PROGRAMMERS 64062: 징검다리 건너기 (0) | 2021.01.25 |
KOREATECH 1074: 유일한 수 두개 (0) | 2021.01.23 |
KOREATECH 1046: 빠른 길 찾기 (0) | 2021.01.22 |
KOREATECH 1043: 위성 사진 (0) | 2021.01.21 |
댓글