-
[Python] 프로그래머스 / 붕대 감기코딩테스트 2024. 8. 5. 15:13
단순한 구현 문제이다.
정답 코드
from collections import deque def solution(bandage, health, attacks): # [5, 1, 5], 30, [[2, 10], [9, 15], [10, 5], [11, 5]] #시전 시간, 초당 회복량, 추가 회복량 T = deque(map(lambda x : x[0], attacks)) P = deque(map(lambda x : x[1], attacks)) fht = bandage[0] hps = bandage[1] sh = bandage[2] conti = 0 blood = health for t in range(1, T[-1] + 1): #print(t, blood) if t in T : t_ = T.popleft() p_ = P.popleft() blood -= p_ conti = 0 if blood <= 0 : return -1 if not T : return blood else : conti += 1 blood += hps if conti == fht : conti = 0 blood += sh if blood > health : blood = health
'코딩테스트' 카테고리의 다른 글
[Python] 프로그래머스 / PCCP 기출문제 / 퍼즐 게임 챌린지 (0) 2024.09.14 [Python] 프로그래머스 / 전화번호 목록 - 뻘짓한 풀이와 완전 짧은 풀이 (0) 2024.08.07 [Python] 프로그래머스 / 네트워크 (0) 2024.08.05 [Python] 프로그래머스 / 공원 산책 (0) 2024.08.03 [Python] 프로그래머스 / 추억 점수 (0) 2024.08.03