Notice
Recent Posts
Recent Comments
Link
Little Jay
[C++] 백준 1966번 프린터 큐 본문
처음에 큐라고만 써있어서 생으로 QUEUE로만 구현하려고 하다가
이건 좀 아닌거 같은데라는 생각이 들어
우선순위 큐로 구현하였다
#include <iostream>
#include <queue>
using namespace std;
int main() {
int testCase, x;
cin >> testCase;
int document, which;
for (int i = 0; i < testCase; i++) {
cin >> document >> which;
int count = 0;
queue<pair<int, int>> q;
priority_queue <int> pq;
for (int k = 0; k < document; k++) {
cin >> x;
q.push({ k, x });
pq.push(x);
}
while (!q.empty()) {
int index = q.front().first;
int value = q.front().second;
q.pop();
if (pq.top() == value) {
pq.pop();
count++;
if (index == which) {
cout << count << "\n";
break;
}
}
else
q.push({ index, value });
}
}
return 0;
}'알고리즘 > BOJ' 카테고리의 다른 글
| [C++] 백준 5054번 주차의 신 (0) | 2021.07.16 |
|---|---|
| [C++] 백준 9012번 괄호 (0) | 2021.07.16 |
| [C++] 백준 1676번 팩토리얼 0의 개수 (0) | 2021.06.28 |
| [C++] 백준 1929번 소수 구하기 (0) | 2021.06.21 |
| [C++] 백준 16395번 파스칼의 삼각형 (0) | 2021.05.10 |
Comments