최소힙트리 그렸다.
def heap_sort(node):
mom_node = node//2
if mom_node < 0:
return
else:
if tree[mom_node] > tree[node]:
tree[node], tree[mom_node] = tree[mom_node], tree[node]
heap_sort(mom_node)
for test in range(1,int(input())+1):
N = int(input())
tree = [0]
node_num = 1
for num in map(int, input().split()):
tree.append(num)
heap_sort(node_num)
node_num += 1
sum_value = 0
while N:
N //= 2
sum_value += tree[N]
print(f'#{test} {sum_value}')
'practivceAlgorithm > swexpertacademy' 카테고리의 다른 글
[SWEA][Python] 1223 계산기2 (0) | 2021.08.24 |
---|---|
[SWEA][Python] 5178 노드의 합 (0) | 2021.08.24 |
[SWEA][Python] 5176 이진 탐색 (0) | 2021.08.24 |
[SWEA][Python] 5174 subtree (0) | 2021.08.24 |
[SWEA][Python] 5122 수열편집 (0) | 2021.08.24 |