Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- coding
- 코테
- 정석
- 정석학술정보관
- OS
- 개발
- 백준
- 오퍼레이팅시스템
- 북리뷰
- 그래프
- Operating System
- 브루트포스
- 컴퓨터공학과
- 알고리즘
- Stack
- 구현
- 자료구조
- Computer science
- 오에스
- 컴공
- vector
- bfs
- 문제풀이
- c++
- 너비우선탐색
- cs
- 컴공과
- 스택
- 코딩
- DP
Archives
- Today
- Total
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