[개발]programmers/Python3

Lv.3_기지국 설치

dowon 2024. 6. 4. 14:03

https://school.programmers.co.kr/learn/courses/30/lessons/12979?language=python3

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

import math

def solution(n, stations, w):
    
    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))
    
    cnt = 0
    for d in distance:
        if d < 0:
            continue
        else:
            cnt += math.ceil(d/ (w*2+1))
    
    return cnt

 

dfs와 같이 어려운 코딩 방법을 시도하기 전에

수학적으로 접근하여 쉽게 풀어보자