import sys
# 입력 초기화
n = int(input())
color_paper = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]
# white, blue 총 갯수
w = 0
b = 0
# cut 함수
def cut(x, y, n):
global w, b
check = color_paper[x][y]
for i in range(x, x + n):
for j in range(y, y + n):
if color_paper[i][j] != check:
# 1사분면
cut(x, y, n // 2)
# 2사분면
cut(x, y + n//2, n // 2)
# 3사분면
cut(x + n//2, y, n // 2)
# 4사분면
cut(x + n//2, y + n//2, n // 2)
return
if check == 0:
w += 1
return
else:
b += 1
return
cut(0, 0, n)
print(w)
print(b)
재귀 함수에 대해 다시 한번 공부하게 되었다.
return은 재귀함수에서 꼭 필요한 존재 이니까 기억하자
'알고리즘' 카테고리의 다른 글
<백준> 11279번 파이썬 알고리즘 [최대 힙] (0) | 2021.11.02 |
---|---|
<백준> 7662번 파이썬 알고리즘 [최소,최대 힙] (0) | 2021.11.02 |
<백준> 1764번 파이썬 알고리즘 (0) | 2021.10.30 |
<백준> 1697번 파이썬 알고리즘 (0) | 2021.10.29 |
<백준> 1676번 자바 알고리즘 (0) | 2021.10.23 |