본문 바로가기

알고리즘

[프로그래머스/PCCP_1번] 붕대 감기(파이썬)

728x90

문제 설명

이 문제는 게임을 하다 보면 치료를 통해 게임 캐릭터의 피를 회복하는 경우를 문제로 하고 있다.

def solution(bandage, health, attacks):
    answer = health
    healing = 0
    t = 0
    max_time = attacks[-1][0]
    at = {}
    
    
    for i in range(len(attacks)):
        at[attacks[i][0]] = attacks[i][1]
    
    
    while t <= max_time:
        if t in at:
            healing = 0
            answer -= at[t]
            
            if answer <= 0:
                return -1
        else:
            healing += 1
            if healing < bandage[0]:
                answer += bandage[1]
                if answer > health:
                    answer = health
            else:
                answer += bandage[1] + bandage[2]
                if answer > health:
                    answer = health
                healing = 0
        t += 1
                    
    return answer

 

 

문제 링크: https://school.programmers.co.kr/learn/courses/30/lessons/250137

728x90