Created
November 6, 2019 06:52
-
-
Save inspirit941/6895f77008f49bc84a96007085f198f1 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
import math | |
def solution(n, stations, w): | |
result = 0 | |
distance = [] | |
# 설치된 기지국 사이에 전파가 닿지 않는 거리를 저장한다 | |
for i in range(1, len(stations)): | |
distance.append((stations[i]-w-1) - (stations[i-1]+w)) | |
# 맨 앞 기지국에서 첫 번째 아파트 사이에 전파가 닿지 않는 거리, | |
# 맨 뒤 기지국에서 마지막 아파트 사이에 전파가 닿지 않는 거리를 저장한다 | |
distance.append(stations[0]-w-1) | |
distance.append(n - (stations[-1]+w)) | |
for i in distance: | |
# 닿지 않는 거리가 0 이하일 경우 스킵한다 | |
if i <=0: continue | |
# 닿지 않는 거리에 설치할 수 있는 최소개수를 더해준다. | |
result += math.ceil(i / ((w*2) +1)) | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment