728x90
SMALL
위 그림을 보면 이해 쉽게 가능 ^__^
저렇게 잘라가며 재귀함수 쓰면 끄읕 !
n = int(input())
arr = list()
for _ in range(n):
arr.append(list(map(int,input().split())))
white=0
blue=0
def check(x,y,m):
color = arr[x][y]
global white,blue
for i in range(x,x+m):
for j in range(y,y+m):
if color!=arr[i][j]:
check(x,y,m//2)
check(x, y+m//2, m // 2)
check(x+m//2, y, m // 2)
check(x+m//2, y+m//2, m // 2)
return
if color==0:
white+=1
else:
blue+=1
check(0,0,n)
print(white)
print(blue)
728x90
LIST
'취준시절 > 백준' 카테고리의 다른 글
[백준 1780] Python - 종이의 개수 (0) | 2021.08.25 |
---|---|
[백준 1991] Python - 트리 순회 (0) | 2021.08.25 |
[백준 1932] Python - 정수 삼각형 (0) | 2021.08.24 |
[백준 12015번] Python - 가장 긴 증가하는 부분 수열 2 (0) | 2021.08.24 |
[백준 2667] Python - 단지번호붙이기 (0) | 2021.08.24 |