Notice
Recent Posts
Recent Comments
- Today
- Total
01-10 22:06
Tags
- leetcode
- Algorithm
- ๋ฐฑ์๋
- ๋ฐ์ดํฐ๋ฒ ์ด์ค
- Graph
- ์ธํด
- dp
- ๋ฒจ๋งํฌ๋
- PS
- ๊ทธ๋ฆฌ๋
- ์๋ฐ
- BFS
- ์๋ฃ๊ตฌ์กฐ
- CS
- ์์์ ๋ ฌ
- ์๋ฐ์์ ์
- array
- spring
- ๋ค์ต์คํธ๋ผ
- OOP
- pytorch
- java
- ๋ฌธ๋ฒ
- ๋ฐฑ์ค
- ๊ตฌํ
- database
- ์กธ์ ์ํ
- tree
- ํ๋ก๊ทธ๋๋จธ์ค
- MST
Link
Partially Committed
[ํ๋ก๊ทธ๋๋จธ์ค] ๊ธฐ๋ฅ๊ฐ๋ฐ ๋ณธ๋ฌธ
728x90
๋ฐ์ํ
SMALL
https://school.programmers.co.kr/learn/courses/30/lessons/42586#
์์ 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
'๐ฅ Algorithm || ๋ฌธ์ ํ์ด > PS' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ๋ก๊ทธ๋๋จธ์ค] ์์์ฐพ๊ธฐ (0) | 2022.07.13 |
---|---|
[ํ๋ก๊ทธ๋๋จธ์ค] ๊ฐ์ฅ ํฐ ์ (0) | 2022.07.13 |
[2017 ํ์คํ์ด] ์ง์ง์ด ์ ๊ฑฐํ๊ธฐ (0) | 2022.07.11 |
[2019 ์นด์นด์ค ๊ฐ๋ฐ์ ๊ฒจ์ธ ์ธํด์ญ] ํํ (0) | 2022.07.11 |
[ํ๋ก๊ทธ๋๋จธ์ค] ๋ ๋งต๊ฒ (0) | 2022.07.11 |
Comments