[BOJ] 1449 수리공 항승

[BOJ] 1449 수리공 항승

문제 링크

주어진 테이프 길이와 간격이 일정하기 때문에 최선의 선택이 존재한다고 보았다.

풀이는 생각보다 어려웠다.

어떻게 풀어야할지 감이 안 잡히다가 startPoint라는 변수를 만들어서 startPoint를 기준으로 테이프 길이+(0.5*2) 와 비교하여 테이프 소모 갯수를 판단하자고 생각이 들어서 그렇게 했다.

나의 풀이

N, L = map(int, input().split(" "))
points = list(map(int, input().split(" ")))
count = 0
startPoint = 0

points.sort()
startPoint = points[0]


for i in range(len(points)+1): #point 갯수만큼 실행
    if i == (len(points)):
      count+=1
      break
    elif(points[i] - startPoint + 1 <= L):
      continue
    else:
      count+=1
      startPoint = points[i]

print(count)

© 2021. All rights reserved.