알고리즘

<백준> 1992번 파이썬 알고리즘 [분할 정복]

changha. 2021. 11. 8. 22:49
import sys

n = int(sys.stdin.readline())
arr = []
for _ in range(n):
  arr.append(list(map(int, input())))


def divide(x, y, n):
  check = arr[x][y]
  for i in range(x, x + n):
    for j in range(y, y + n):
      if check != arr[i][j]:
        check = -1
        break
  
  if check == -1:
    print('(', end="")
    n = n//2
    divide(x, y, n)
    divide(x, y + n, n)
    divide(x + n, y, n)
    divide(x + n, y + n, n)
    print(')',end="")

  elif check == 0:
    print("0", end="")
  else:
    print("1", end="")

divide(0, 0, n)

( 를 어떻게 표현할까 고민했었다

https://tmdrl5779.tistory.com/102

 

[백준] 1992번 (python 파이썬)

백준 2630문제와 같은 문제이다. tmdrl5779.tistory.com/101 [백준] 2630번 (python 파이썬) Divide and Conquer에 대한 문제이다. 1. 해당 종이가 일괄된 색이 아니면 4등분을 한다. 2. 4등분된 종이를 다시 검..

tmdrl5779.tistory.com

위 블로그에서 출력을 그냥 print로 간단히 하는 방법을 배웠다