728x90
๋ฐ์ํ
https://school.programmers.co.kr/learn/courses/19344/lessons/242258
ํ๋ก๊ทธ๋๋จธ์ค
SW๊ฐ๋ฐ์๋ฅผ ์ํ ํ๊ฐ, ๊ต์ก, ์ฑ์ฉ๊น์ง Total Solution์ ์ ๊ณตํ๋ ๊ฐ๋ฐ์ ์ฑ์ฅ์ ์ํ ๋ฒ ์ด์ค์บ ํ
programmers.co.kr
ํ๋ก๊ทธ๋๋ฐ ๊ฐ์ ไธญ PCCP ๊ธฐ์ถ๋ฌธ์ : 1๋ฒ ๋ถ๋ ๊ฐ๊ธฐ (ํ๋ก๊ทธ๋๋จธ์ค ๋ ๋ฒจ 1 ๋ฌธ์ )
์์์๊ฐ ์ฝ 23๋ถ
๋จ์ ๊ตฌํ or ํ ๋ฌธ์ , ๋์ด๋ level 1-2 ์ถ์
์ฐ์ ์์ ํ๋ฅผ ์ฌ์ฉํด๋ ๋์ง๋ง, ์ ๋ ฌ ํ ๋จ์ ๊ตฌํ์ด ๊ฐ๋ฅํ๋ค
์ฌ๋ฌ ์กฐ๊ฑด์ ์ ํ์ ํด์ ํ์ฉํ๋ ๋ฌธ์
๋์ ํ์ด
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
int t; int x; int y;
int nowHealth(int max, int health, int state){ // ํ์ฌ ์ฒด๋ ฅ ๊ณ์ฐ
if(health < max) {
health += x;
if(state == t){
health += y;
}
}
if(health > max) return max;
return health;
}
int solution(vector<int> bandage, int health, vector<vector<int>> attacks) {
t = bandage[0]; // t์ด ๋์
x = bandage[1]; // 1์ด์ x์ฉ ํ๋ณต
y = bandage[2]; // t์ด ์๋ฃ ์, ์ถ๊ฐ ํ๋ณต
int maxHealth = health;
int index = 0; // ๊ณต๊ฒฉ ์ธ๋ฑ์ค
int state = 0; // ์ฐ์ ์ฑ๊ณต ์ํ
int time = 0; // ํ์ฌ ์๊ฐ
sort(attacks.begin(), attacks.end()); // ์๊ฐ์ ์ ๋ ฌ
while(health>0 && index < attacks.size()){
if(time >= attacks[index][0]){
int damage = attacks[index][1];
health -= damage;
if(health < 0) break;
state = 0;
index++;
}
else health = nowHealth(maxHealth, health, state);
if(index >= attacks.size()) break;
if(state == t) state = 0;
time++;
state++;
}
if(health<=0) return -1;
return health;
}
728x90
๋ฐ์ํ
'๐ ์๊ณ ๋ฆฌ์ฆ > Programmers' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[C++/PGS] Lv.1 : ๋์์ ์ฌ์๊ธฐ (PCCP ๊ธฐ์ถ๋ฌธ์ 1๋ฒ) (0) | 2025.05.02 |
---|---|
[C++/PGS] [PCCP ๊ธฐ์ถ๋ฌธ์ ] 4๋ฒ - ์๋ ์์ง์ด๊ธฐ (1) | 2025.05.02 |
[C++/PGS] [PCCP ๋ชจ์๊ณ ์ฌ #1] 3๋ฒ - ์ ์ ๋ฒ์น ๐คฏ (0) | 2025.05.02 |
[C++/PGS] [PCCP ๋ชจ์๊ณ ์ฌ #1] 2๋ฒ - ์ฒด์ก๋ํ (0) | 2025.05.02 |
[C++/PGS] [PCCP ๋ชจ์๊ณ ์ฌ #1] 1๋ฒ - ์ธํจ์ด ์ํ๋ฒณ (0) | 2025.05.02 |