-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path기지국 설치.py
46 lines (35 loc) · 1015 Bytes
/
기지국 설치.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
'''
import math
def solution(N, stations, W):
breakpoint = 0
ans = 0
for num in stations:
ans += math.ceil(((num-W-1)-breakpoint)/(1+(2*W)))
breakpoint = num + W
if breakpoint < N:
ans += math.ceil((N-breakpoint)/(1+(2*W)))
return ans
'''
'''
#동시에 이렇게도 풀어 보았다. 아래의 방법으로 푸는 것이 실수가 적을듯 하다.
import math
def solution(N, stations, W):
stations = [W*-1] + stations
stations.append(N+W+1)
ans = 0
for i in range(0,len(stations)-1):
if stations[i+1] - stations[i] > W*2:
ans += math.ceil(((stations[i+1] - stations[i]) - (1+W*2))/(1+(2*W)))
return ans
'''
#2020.05.13
import math
def solution(N, stations, W):
checkpoint = 0
cnt = 0
for a in stations:
cnt += math.ceil(((a-W)-1 - checkpoint)/((W*2)+1))
checkpoint = a+W
if (N - checkpoint) > 0:
cnt += math.ceil((N - checkpoint)/((W*2)+1))
return cnt