🔻PS/Programmers

[Programmers] 프로그래머스 붕대 감기 Python

_니지 2024. 7. 16. 11:18

https://school.programmers.co.kr/learn/courses/30/lessons/250137

 

프로그래머스

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

programmers.co.kr

 

# t초 동안 붕대 감기 
# 1초마다 x만큼 회복 => 총 t*x만큼 회복
# t초 연속으로 붕대 감기 성공 => +y체력

# 공격 당해서 기술 취소 or 연속 성공 0으로 초기화
# 체력이 0 이하 되면 그냥 끝


def solution(bandage, health, attacks):
    # bandage: t초, 1초당 회복량, y
    # health: 최대 체력
    
    max_health = health
    
    success = 0
    time = [x[0] for x in attacks]

    
    
    for t in range(1, max(time)+1):
        if t in time: 
            success = 0
            attacked = attacks[time.index(t)][1]
            health -= attacked
        else:
            success += 1
            health += bandage[1]

    
        # 1. 연속 성공 달성 여부 -> 추가 최복이 있기 때문
        if success == bandage[0]:
            health += bandage[2]
            success = 0
        
        # 2. max를 넘기면 max로 제한
        if health > max_health:
            health = max_health ###
        
        # 3. 0 이하면 -1
        if health <= 0:
            return -1

    
    return health
728x90
반응형