https://www.acmicpc.net/problem/9934
#9934_완전이진트리
import sys
input = sys.stdin.readline
K=int(input())
tree = list(map(int,input().split()))
bin_tree = [[] for _ in range(K)]
def binary_search(tree,depth):
if len(tree)==1:#last layer
bin_tree[depth].extend(tree)
return
mid = len(tree) // 2
bin_tree[depth].append(tree[mid])
binary_search(tree[:mid],depth+1)
binary_search(tree[mid+1:],depth+1)
binary_search(tree,0)
for i in range(K):
if i==0:
print(bin_tree[i][0])
else:
print(*bin_tree[i])
'알고리즘 > 백준(BOJ)' 카테고리의 다른 글
[백준/알고리즘] #5639: 이진검색트리 [파이썬(python)/트리] (0) | 2021.10.18 |
---|---|
[백준/알고리즘] #1991: 트리순회 [파이썬(python)/트리] (0) | 2021.10.18 |
[백준/알고리즘] #11279: 최대 힙 [파이썬(python)/자료구조/우선순위 큐] (0) | 2021.10.18 |
[백준/알고리즘] #2475: 검증수 [파이썬(python)/수학] (0) | 2021.10.18 |
[백준/알고리즘] #2576: 홀수 [파이썬(python)/수학] (0) | 2021.10.18 |