알고리즘/programmers

[PCCP 기출문제] 1번 / 붕대 감기

꾸준함. 2023. 11. 27. 23:13

문제 링크입니다: https://school.programmers.co.kr/learn/courses/30/lessons/250137

 

프로그래머스

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

programmers.co.kr

 

문제에서 주어진 대로 풀면 되는 간단한 구현 문제였습니다.

 

#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;
}
view raw .cpp hosted with ❤ by GitHub

 

개발환경: Programmers IDE

 

지적, 조언, 질문 환영합니다! 질문 남겨주세요~ 

반응형