백준 16434번 드래곤 앤 던전

DARTZ·2022년 5월 17일
0

알고리즘

목록 보기
61/135
import sys
sys.stdin = open('input.txt', 'rt')
input = sys.stdin.readline

N, H = map(int, input().split())

rooms = []

for _ in range(N):
    rooms.append(list(map(int, input().split())))

start = 1
end = 1000000

while start <= end:
    max_hp = (start + end) // 2 # 이분탐색의 중간값 여기선 최대 hp이므로 max_hp로 변수명 설정
    monster_hp = 0
    monster_attack = 0
    current_attack = H
    current_hp = max_hp

    print(max_hp)

    for room in rooms:
        if room[0] == 1:
            temp = room[2] // current_attack
            if room[2] % current_attack != 0:
                temp = temp + 1

            current_hp = current_hp - (temp * room[1])

        else:
            current_attack = current_attack + room[1]
            current_hp = current_hp + room[2]

    if current_hp <= 1:
        start = max_hp + 1

    else:
        answer = max_hp
        end = max_hp - 1

print(answer)

코드 임시 저장..

profile
사람들이 비용을 지불하고 사용할 만큼 가치를 주는 서비스를 만들고 싶습니다.

0개의 댓글