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

2026. 3. 23. 11:23·Algorithm

문제

 

 

풀이

def solution(bandage, health, attacks):
	#최대 체력, 현재 시간 설정
    max_health = health
    time_now = 0
    for attack in attacks :
    	#현재 시간에서 다음 공격까지는 붕대를 감는 시간
        healing_time = attack[0] - time_now
        
        #healing time
        #붕대 감기 시전시간 이상의 healing time있을 시에, 추가 회복
        if healing_time // bandage[0] >= 1 :
            health += (healing_time // bandage[0]) * bandage[2]
            
        #초당 회복량
        health += healing_time * bandage[1]
        
        #max_health를 넘을 수 없으므로
        if health > max_health :
            health = max_health
            
        #attack
        health -= attack[1]
        if health <= 0 :
            return -1
            
        #공격 이후부터 회복을 시작하므로 time_now 설정
        time_now = attack[0] + 1
        
    return health

 

 

1. 최대 체력(max_health), 현재 시간(time_now)설정

2. 현재시간 ~ 다음 공격까지 붕대를 감는 시간(healing time)

3. healing time이 붕대감기 시전 시간보다 클 경우, 추가 회복량 계산

4. healing time 동안 초당 회복량 계산, 하지만 max_health넘을 수 없음

5. attack time : 체력이 0 이하가 되면 -1 return 하면서  break

6. 공격 다음 초부터 붕대를 감기 시작하므로 time_now를 attack시점부터 + 1

7. 모든 공격이 끝난 후 health return

 

 

GitHub Link    ←

 

BackJoon-Programmers/프로그래머스/1/250137. [PCCP 기출문제] 1번 / 붕대 감기 at main · jaeheonk

Contribute to jaeheonki/BackJoon-Programmers development by creating an account on GitHub.

github.com

 

'Algorithm' 카테고리의 다른 글

[프로그래머스] 짝지어 제거하기  (4) 2026.04.01
[프로그래머스] 최댓값과 최솟값  (2) 2026.03.30
[프로그래머스] 달리기 경주  (0) 2026.03.23
[프로그래머스] 개인정보 수집 유효기간  (3) 2026.03.20
[프로그래머스] [PCCE 기출문제] 10번 / 데이터 분석  (0) 2026.03.20
'Algorithm' 카테고리의 다른 글
  • [프로그래머스] 짝지어 제거하기
  • [프로그래머스] 최댓값과 최솟값
  • [프로그래머스] 달리기 경주
  • [프로그래머스] 개인정보 수집 유효기간
uj07096
uj07096
개발블로그 시작 !
  • uj07096
    김재헌 님의 블로그
    uj07096
  • 전체
    오늘
    어제
    • 분류 전체보기 N
      • Algorithm
      • My IT
        • Article
        • Codes
      • TIL
      • My Projects N
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    Algorithm
    GAN
    PyTorch
    transfer learning
    Faster R-CNN
    ResNet
    데이터전처리
    AI
    파이썬
    머신러닝
    EDA
    Stack
    DenseNet
    LSTM
    YOLO
    kaggle
    이상치
    LeetCode
    autoencoder
    til
    딥러닝
    DeepLearning
    Tensor
    코딩테스트
    EfficientNet
    프로그래머스
    코테
    python
    convolution
    optuna
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.6
uj07096
[프로그래머스] 붕대 감기
상단으로

티스토리툴바