Lv.1 [PCCP 기출문제] 1번

2023. 12. 5. 15:25CS&알고리즘/프로그래머스

✏️ 문제 

 

Python 

def solution(bandage, health, attacks):

    # 초기 상태 설정
    nowHealth = health # 현재 체력
    success = 0 # 연속 성공
    sec = 0 #현재 시간

    t = bandage[0] # 시전 시간
    x = bandage[1] # 초당 회복량
    y = bandage[2] # 추가 회복량

    while nowHealth > 0 and attacks :
        # 초 시간 증가
        sec += 1


        # 공격 시간 확인
        if (attacks[0][0] == sec) :
            nowHealth -= attacks[0][1]
            success = 0


            del attacks[0]
            if (nowHealth < 1) :
                return -1
        else:
            # 초당 회복량 증가
            nowHealth += x

            # 연속 성공 증가
            success += 1
            if (success == t) :
                # 연속 성공한 경우 추가 회복
                nowHealth += y
                success = 0


        # 회복량이 최대 회복량보다 큰 경우
        if (nowHealth > health) :
            nowHealth = health


    return nowHealth

 

Java

자바 풀이는 추후 반영 예정..