티스토리 뷰

문제 링크

 

코딩테스트 연습 - 기능개발

프로그래머스 팀에서는 기능 개선 작업을 수행 중입니다. 각 기능은 진도가 100%일 때 서비스에 반영할 수 있습니다. 또, 각 기능의 개발속도는 모두 다르기 때문에 뒤에 있는 기능이 앞에 있는 ��

programmers.co.kr

 

 

 

풀이

큐를 사용하였다.

 

요약하자면,

// init

남은 일수에 대해서 모두 큐에 넣어줌.

 

// process

반복문 - 큐가 빌 때까지

{

    해당 큐의 맨 앞 원소값를 "cur" 변수에 저장

    반복문 - 큐가 빌 때까지

    {

        해당 큐에 "cur" 변수보다 작을 때까지 pop()하면서 count를 센다.

    }

}

 

 

더보기
#include <string>
#include <vector>
#include <queue>

using namespace std;

// 먼저 배포되어야 하는 순서의 진도율 progresses
// 개발 속도 speeds

vector<int> solution(vector<int> progresses, vector<int> speeds) {
    vector<int> answer;
    queue<int> q;
    
    // init
    for(int i=0; i<progresses.size(); i++){
        int prog = 100 - progresses[i];
        int remain = prog / speeds[i];     // 남은 일수
        remain = prog%speeds[i]!=0 ? remain+1 : remain;       // 나머지가 있으면 하루 더 추가
        q.push(remain);
    }
    
    // process
    while(!q.empty()){
        int count = 0;
        int cur = q.front();
        while(!q.empty()){
            if(q.front() > cur) break;
            q.pop();
            count++;
        }
        answer.push_back(count);
    }
    
    return answer;          // 각 배포되는 순서마다 몇 개의 기능이 배포되는지 개수 리턴
}
728x90
반응형
댓글
05-04 11:41
링크