문제 링크입니다: https://school.programmers.co.kr/learn/courses/30/lessons/250137
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
문제에서 주어진 대로 풀면 되는 간단한 구현 문제였습니다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
#include <vector> | |
using namespace std; | |
int solution(vector<int> bandage, int health, vector<vector<int>> attacks) { | |
int answer = health; | |
int idx = 0; | |
int lastIdx = attacks.size() - 1; | |
int consecutive = 0; | |
for (int time = 1; time <= attacks[lastIdx][0]; time++) | |
{ | |
if (attacks[idx][0] == time) | |
{ | |
answer -= attacks[idx++][1]; | |
if (answer <= 0) | |
{ | |
return -1; | |
} | |
consecutive = 0; | |
continue; | |
} | |
answer = min(answer + bandage[1], health); | |
if (++consecutive == bandage[0]) | |
{ | |
answer = min(answer + bandage[2], health); | |
consecutive = 0; | |
} | |
} | |
return answer; | |
} |

개발환경: Programmers IDE
지적, 조언, 질문 환영합니다! 질문 남겨주세요~
반응형
'알고리즘 > programmers' 카테고리의 다른 글
[PCCP 기출문제] 4번 / 수레 움직이기 (2) | 2023.11.29 |
---|---|
[PCCP 기출문제] 2번 / 석유 시추 (0) | 2023.11.28 |
[Programmers] 카운트 다운 (0) | 2023.11.16 |
[Programmers] 부대복귀 (0) | 2023.11.04 |
[Programmers] 2차원 동전 뒤집기 (0) | 2023.10.20 |