Created
November 27, 2019 06:57
-
-
Save inspirit941/13e638928e38e7008a176d63a8a5d1dd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def solution(routes): | |
# 도로의 맨 앞에서부터 감시카메라 설치. | |
routes = [[i[0], i[1]] for i in sorted(routes, key = lambda x: (x[0]))] | |
result = [routes.pop(0)] | |
for compare in routes: | |
idx = 0 | |
while idx != len(result): | |
# 만약 새 차량의 진입시점 / 진출시점이 기존 카메라 설치 범위에 들어간다면 | |
if (result[idx][0] <= compare[0] <= result[idx][1]) or (result[idx][0] <= compare[1] <= result[idx][1]): | |
# 감시카메라가 새 차량을 감지할 수 있도록 감시카메라의 위치 조정 | |
result[idx][0] = compare[0] if compare[0] > result[idx][0] else result[idx][0] | |
result[idx][1] = compare[1] if compare[1] < result[idx][1] else result[idx][1] | |
break | |
else: | |
idx +=1 | |
# 만약 감시카메라 설치 위치를 전부 돌았는데도 감지가 안 된다면 | |
# 차량을 감시할 수 있는 새 감시카메라를 설치해야 한다. | |
if idx == len(result): | |
result.append(compare) | |
return len(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment