๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ“ ์•Œ๊ณ ๋ฆฌ์ฆ˜/Programmers

[C++/PGS] [PCCP ๊ธฐ์ถœ๋ฌธ์ œ] 1๋ฒˆ - ๋ถ•๋Œ€ ๊ฐ๊ธฐ

by xxilliant 2025. 5. 2.
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
๋ฐ˜์‘ํ˜•