안녕하세요.. 현재 대학과제를 하고있는데... 몇일 동안 고민해도 도저히 해결못해서 이렇게 질문을 하게 되었습니다.,,만
위 문제인데요...
def get_skyline(buildings): if not buildings: return [] if len(buildings) == 1: return [[buildings[0][0], buildings[0][2]], [buildings[0][1], 0]] mid = len(buildings) // 2 left = get_skyline(buildings[:mid]) right = get_skyline(buildings[mid:]) return merge(left, right) def merge(left, right): h1, h2 = 0, 0 i, j = 0, 0 result = [] while i < len(left) and j < len(right): if left[i][0] < right[j][0]: h1 = left[i][1] corner = left[i][0] i += 1 elif right[j][0] < left[i][0]: h2 = right[j][1] corner = right[j][0] j += 1 else: h1 = left[i][1] h2 = right[j][1] corner = right[j][0] i += 1 j += 1 if is_valid(result, max(h1, h2)): result.append([corner, max(h1, h2)]) result.extend(right[j:]) result.extend(left[i:]) return result def is_valid( result, new_height): return not result or result[-1][1] != new_height num=int(input()) test=[[]*i for i in range(num)] for i in range(num): x, h, y = input().split() x = int(x) h = int(h) y = int(y) test[i]=[x,x+y,h] result=get_skyline(test) print(result)
input
2
7 6 5
10 5 9
output
[[7, 6], [12, 5], [19, 0]]
이렇게
변하는 꼭지점까지는 구햇는데, 여기서 윤곽을 따라가는 코드를 만들며되는데.. 조언좀 해주세요 ㅠ