Notice
Recent Posts
Recent Comments
- Today
- Total
02-12 04:30
Tags
- array
- leetcode
- ์ธํด
- MST
- ๋ฐฑ์ค
- Algorithm
- ์์์ ๋ ฌ
- ํ๋ก๊ทธ๋๋จธ์ค
- Graph
- CS
- tree
- ์๋ฐ์์ ์
- database
- ์๋ฃ๊ตฌ์กฐ
- ๊ทธ๋ฆฌ๋
- spring
- ์๋ฐ
- ๋ฐฑ์๋
- PS
- pytorch
- dp
- ๋ฒจ๋งํฌ๋
- ๊ตฌํ
- ๋ฌธ๋ฒ
- OOP
- java
- ์กธ์ ์ํ
- ๋ฐ์ดํฐ๋ฒ ์ด์ค
- ๋ค์ต์คํธ๋ผ
- BFS
Link
Partially Committed
[ํ๋ก๊ทธ๋๋จธ์ค] ๋ ๋งต๊ฒ ๋ณธ๋ฌธ
728x90
๋ฐ์ํ
SMALL
https://school.programmers.co.kr/learn/courses/30/lessons/42626#
ํ๋ก๊ทธ๋๋จธ์ค
์ฝ๋ ์ค์ฌ์ ๊ฐ๋ฐ์ ์ฑ์ฉ. ์คํ ๊ธฐ๋ฐ์ ํฌ์ง์ ๋งค์นญ. ํ๋ก๊ทธ๋๋จธ์ค์ ๊ฐ๋ฐ์ ๋ง์ถคํ ํ๋กํ์ ๋ฑ๋กํ๊ณ , ๋์ ๊ธฐ์ ๊ถํฉ์ด ์ ๋ง๋ ๊ธฐ์ ๋ค์ ๋งค์นญ ๋ฐ์ผ์ธ์.
programmers.co.kr
์ค์ฝ๋น ์ง์๊ฐ ๊ธฐ๋ก๋ scoville ๋ฐฐ์ด์์ K ๋ณด๋ค ์์ scoville ์ ๊ฐ์ง ์์๊ฐ ์๋ค๋ฉด ์ต์ scoville ์, ๊ทธ ๋ค์์ผ๋ก ํฐ scoville ์ ์ด์ฉํ์ฌ ์๋ก์ด ์์๋ฅผ ์ถ๊ฐํ๋ค. ์ด๋ฅผ ์ํด์ ์ต์ํ์ ์ฌ์ฉํ๋ค.
#include <string>
#include <vector>
#include <queue>
#include <functional>
#include <iostream>
#define ll long long
using namespace std;
int solution(vector<int> scoville, int K) {
priority_queue <int, vector<int>, greater<int> > pq;
for(auto & ele : scoville)
{
pq.push(ele);
}
int cnt = 0; int mixed = 0; int first = 0; int second = 0;
while(pq.size()!=1)
{
if(pq.top() >= K) break;
first = pq.top();
pq.pop();
second = pq.top();
pq.pop();
mixed = first + second + second;
pq.push(mixed);
cnt++;
}
if(pq.top() < K) return -1;
return cnt == 0 ? -1 : cnt;
}
728x90
๋ฐ์ํ
LIST
'๐ฅ Algorithm || ๋ฌธ์ ํ์ด > PS' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[2017 ํ์คํ์ด] ์ง์ง์ด ์ ๊ฑฐํ๊ธฐ (0) | 2022.07.11 |
---|---|
[2019 ์นด์นด์ค ๊ฐ๋ฐ์ ๊ฒจ์ธ ์ธํด์ญ] ํํ (0) | 2022.07.11 |
[ํ๋ก๊ทธ๋๋จธ์ค] ์ ํ๋ฒํธ ๋ชฉ๋ก (0) | 2022.07.08 |
[2020 KAKAO BLIND RECRUITMENT] ๊ดํธ ๋ณํ (0) | 2022.07.08 |
[2019 KAKAO BLIND RECRUITMENT] ์คํ์ฑํ ๋ฐฉ (0) | 2022.07.07 |
Comments