Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- Brightics Studio
- 추천시스템
- 삼성SDS
- 데이터 분석
- Brigthics를 이용한 분석
- 팀 분석
- 브라이틱스
- 브라이틱스 서포터즈
- 혼공
- 혼공학습단
- 삼성 SDS
- 직원 이직률
- 삼성SDS Brigthics
- 포스코 아카데미
- 혼공머신러닝딥러닝
- Brightics
- 데이터분석
- 영상제작기
- Brigthics Studio
- 삼성 SDS Brigthics
- 캐글
- 모델링
- Brigthics
- 혼공머신
- Brightics를 이용한 분석
- 삼성SDS Brightics
- 개인 의료비 예측
- 포스코 청년
- 직원 이직여부
- 노코드AI
Archives
- Today
- Total
데이터사이언스 기록기📚
[프로그래머스/Python] Level 3_기지국 설치 본문
📌문제 유형
Summer/Winter Coding(~2018), 그리디, 구현
📌문제
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
📌나의 문제풀이
- 점수 : 93.3
- station별 전파 가능한 곳 min_s(가장 작은 값), max_s(가장 큰 값) 저장
- 이전 비어 있는 범위 range_에 저장
- 기지국 수 range_ / (2w+1) 올림한 값
from math import ceil
def solution(n, stations, w):
answer = 0
start = 0
for station in stations:
min_s, max_s = station - w, station + w
range_ = min_s - start - 1
answer += ceil(range_ / (2*w+1))
start = max_s
if start < n:
range_ = n - start - 1
answer += ceil(range_ / (2*w+1))
return answer
-정답
- if start < n 구문에서 n이 포함되므로 range_의 -1 제외
from math import ceil
def solution(n, stations, w):
answer = 0
start = 0
for station in stations:
min_s, max_s = station - w, station + w
range_ = min_s - start - 1
# 범위 넘지 않도록 제한
if min_s <= 0:
range_ = 0
# 범위 넘지 않도록 제한
if range_ != 0:
answer += ceil(range_ / (2*w+1))
answer += ceil(range_ / (2*w+1))
start = max_s
if start < n:
range_ = n - start
answer += ceil(range_ / (2*w+1))
return answer
📌다른사람의 문제풀이
- 방식 유사
def solution(n, stations, w):
ans = 0
idx = 0
location = 1
while(location <= n) :
if(idx < len(stations) and location >= stations[idx]-w) :
location = stations[idx]+w+1
idx += 1
else :
location += 2*w+1
ans += 1
return ans
728x90
'Coding Test > 프로그래머스(Python)' 카테고리의 다른 글
[프로그래머스/Python] Level 3_징검다리 건너기 (0) | 2024.03.02 |
---|---|
[프로그래머스/Python] Level 3_가장 먼 노드 (0) | 2024.02.21 |
[프로그래머스/Python] Level 3_보석 쇼핑 (0) | 2024.02.16 |
[프로그래머스/Python] Level 3_불량 사용자 (0) | 2024.02.10 |
[프로그래머스/Python] Level 3_스티커 모으기(2) (0) | 2024.02.09 |
Comments