해당 문제는 각 기능의 현재 진행 상황을 주어주고, 각 기능의 개발 속도를 주어줍니다. 그리고 배포는 100%일때 반영되고 뒤에 있는 기능은 앞에 있는 기능이 배포될 때 함께 배포된다. 즉 뒤에 있는 기능이 먼저 완성되어도 그 앞에 있는 모든 기능이 완성되어야 배포할 수 있다. 배포는 하루에 한 번 이루어집니다. 이때 각 배포마다 몇 개의 기능이 배포되는지 구하는 문제입니다.
우선 기능을 저장하기위한 구조체를 만들어주었습니다. 그리고 구조체에는 현재 기능의 진행 per, 진행하는 속도 up, 해당 기능의 순서 order를 저장해주었습니다. 그리고 queue에 넣고 하나씩 100%인지 확인하고 앞에서 부터 배포가 가능한지 확인(s)해줍니다. 그리고 배포된 갯수(cnt)를 answer에 넣어줍니다.
#include <string>
#include <vector>
#include <queue>
using namespace std;
struct JOB {
int per;
int up;
int order;
};
// 기능 개발
vector<int> solution(vector<int> progresses, vector<int> speeds) {
vector<int> answer;
queue<JOB> q;
for (int i = 0; i < progresses.size(); i++) {
q.push({progresses[i], speeds[i], i});
}
int s = 0;
int cnt = 0;
bool flag = false;
while (q.size()) {
auto f = q.front();
int curPer = f.per;
int curOrder = f.order;
int curUp = f.up;
q.pop();
if (curOrder <= s && curPer >= 100) {
s++;
cnt++;
flag = true;
continue;
}
else {
if (flag) {
answer.push_back(cnt);
flag = false;
cnt = 0;
}
}
q.push({ curPer + curUp, curUp, curOrder });
}
answer.push_back(cnt);
return answer;
}
int main() {
vector<int> progresses;
progresses.push_back(95);
progresses.push_back(90);
progresses.push_back(99);
progresses.push_back(99);
progresses.push_back(80);
progresses.push_back(99);
vector<int> speeds;
speeds.push_back(1);
speeds.push_back(1);
speeds.push_back(1);
speeds.push_back(1);
speeds.push_back(1);
speeds.push_back(1);
vector<int> ans = solution(progresses, speeds);
for (auto el : ans) {
printf("%d\n", el);
}
return 0;
}