Notice
Recent Posts
Recent Comments
Today
Total
01-10 22:06
Link
๊ด€๋ฆฌ ๋ฉ”๋‰ด

Partially Committed

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ๊ธฐ๋Šฅ๊ฐœ๋ฐœ ๋ณธ๋ฌธ

๐Ÿ”ฅ Algorithm || ๋ฌธ์ œํ’€์ด/PS

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ๊ธฐ๋Šฅ๊ฐœ๋ฐœ

WonderJay 2022. 7. 12. 09:30
728x90
๋ฐ˜์‘ํ˜•
SMALL

https://school.programmers.co.kr/learn/courses/30/lessons/42586#

 

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”.

programmers.co.kr

 

์ž‘์—… progresses[i] ์ด ์ž‘์—… ์™„๋ฃŒ๋˜๋ ค๋ฉด 100 - progresses[i] / speeds[i] ์ผ์ด ๊ฑธ๋ฆฐ๋‹ค.

์ด๋•Œ, ํ•ด๋‹น ์ˆ˜์‹์˜ ๊ณ„์‚ฐ์ด 2.xxx ์™€ ๊ฐ™์€ ๊ฒฝ์šฐ 3 ๊ณผ ๊ฐ™์ด ์˜ฌ๋ฆผ ๊ณ„์‚ฐํ•ด์•ผํ•˜๋Š”๋ฐ,

ceil((100 - progresses[i])/speeds[i]) ๋ผ๊ณ  ํ•˜๋ฉด 2.xxx ๊ฐ€ ์ž๋™์œผ๋กœ int ๋กœ ํ˜•๋ณ€ํ™˜๋˜์–ด์„œ ์‚ฌ์‹ค ์˜๋ฏธ์—†๊ฒŒ ๋œ๋‹ค.

๊ทธ๋Ÿฌ๋ฏ€๋กœ, ceil((100 - progresses[i])/(double)speeds[i]) ๊ณผ ๊ฐ™์ด ํ˜•๋ณ€ํ™˜์„ ํ•ด์ฃผ์–ด์•ผ ์›ํ•˜๋Š” ๋Œ€๋กœ ๋™์ž‘ํ•œ๋‹ค.

#include <string>
#include <vector>
#include <queue>
#include <iostream>
#include <math.h>

using namespace std;

vector<int> solution(vector<int> progresses, vector<int> speeds) {
    vector<int> answer;
    queue<int> due_date;
    queue<pair<int, int>> q;
    
    for(int i = 0 ; i < progresses.size(); i++)
        q.push({progresses[i], speeds[i]});
    
    while(!q.empty())
    {
        pair<int, int> cur = q.front();
        q.pop();
        int day = ceil((100-cur.first)/(double)cur.second);    
        due_date.push(day);
    }
    
    
    while(!due_date.empty())
    {
        int i = 0; int cnt = 1;
        int t = due_date.front();
        due_date.pop();
        while(t >= due_date.front() && !due_date.empty())
        {
            cnt++;
            due_date.pop();
        }
        answer.push_back(cnt);
    }
    
    return answer;
}

 

728x90
๋ฐ˜์‘ํ˜•
LIST
Comments