728x90
https://programmers.co.kr/learn/courses/30/lessons/42586
코딩테스트 연습 - 기능개발 | 프로그래머스
프로그래머스 팀에서는 기능 개선 작업을 수행 중입니다. 각 기능은 진도가 100%일 때 서비스에 반영할 수 있습니다. 또, 각 기능의 개발속도는 모두 다르기 때문에 뒤에 있는 기능이 앞에 있는 기능보다 먼저 개발될 수 있고, 이때 뒤에 있는 기능은 앞에 있는 기능이 배포될 때 함께 배포됩니다. 먼저 배포되어야 하는 순서대로 작업의 진도가 적힌 정수 배열 progresses와 각 작업의 개발 속도가 적힌 정수 배열 speeds가 주어질 때 각 배포마다 몇
programmers.co.kr
s = (100 - progresses[i]) % speeds[i];
속도로 남은 진행율을 나눴을 때 나머지가 존재한다면 1일을 더 해야하는 것이므로
s>0 이면 1일만큼 더 더한 값을 push back 해준다.
만약 먼저 처리되어야 하는 일로부터 순차적으로 기능들이 몇일 걸리는 지를 계산할 때
더 오래걸리는 기능을 만난다면 그만큼의 cnt 값을 answer 배열에 푸시해준다.
만약 마지막 기능을 만나면 그 동안의 cnt 값을 push 해주고 끝낸다.
코드
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
int s; | |
using namespace std; | |
vector<int> solution(vector<int> progresses, vector<int> speeds) { | |
vector<int> answer; | |
vector<int> temp; | |
for (int i = 0; i < progresses.size() ; i++) { | |
s = (100 - progresses[i]) % speeds[i]; | |
if (s > 0) { | |
temp.push_back((100 - progresses[i]) / speeds[i] + 1); | |
} | |
else | |
{ | |
temp.push_back((100 - progresses[i]) / speeds[i]); | |
} | |
} | |
s = temp[0]; | |
int cnt = 0; | |
for (int i = 0; i < temp.size(); i++) { | |
if (s < temp[i]) { | |
answer.push_back(cnt); | |
cnt = 1; | |
s = temp[i]; | |
} | |
else { | |
cnt++; | |
} | |
if (i == temp.size() - 1) { | |
answer.push_back(cnt); | |
} | |
} | |
return answer; | |
} |
'프로그래밍 > programmers&bj' 카테고리의 다른 글
[C++][알고리즘] 프로그래머스:: 단어 변환 (DFS) (2) | 2020.03.05 |
---|---|
[C++][알고리즘] 프로그래머스:: 쇠막대기 (0) | 2019.11.18 |
[C++][알고리즘] 백준 16396번 선그리기 (0) | 2019.10.28 |
[C++][알고리즘] 백준 16395번 파스칼의 삼각형 (0) | 2019.09.22 |
[C++][알고리즘] 프로그래머스:: 예산 (0) | 2019.09.10 |