Recent Posts
Notice
No Rules Rules
프린터 큐 (feat. 백준, 1966번) 본문
728x90
반응형
프린터 큐
https://www.acmicpc.net/problem/1966
1966번: 프린터 큐
여러분도 알다시피 여러분의 프린터 기기는 여러분이 인쇄하고자 하는 문서를 인쇄 명령을 받은 ‘순서대로’, 즉 먼저 요청된 것을 먼저 인쇄한다. 여러 개의 문서가 쌓인다면 Queue 자료구조에
www.acmicpc.net
반응형
// woohyeon.kim
// kim519620.tistory.com
#include <iostream>
#include <queue>
using namespace std;
int main()
{
register int T, N, M, arr[100];
cin >> T;
for (register int t = 0, v; t < T; ++t) {
cin >> N >> M;
priority_queue<int> tmp;
queue<pair<int, int>> ans;
for (register int i = 0; i < N; ++i)
cin >> v, ans.push(make_pair(i, v)), tmp.push(v);
register int count = 0;
while (!ans.empty()) {
auto t = ans.front(); ans.pop();
if (tmp.top() == t.second) {
tmp.pop();
++count;
if (M == t.first) {
cout << count << "\n";
break;
}
}
else
ans.push(t);
}
}
return 0;
}
// *&)*@*
728x90
반응형
'생활 > 코테' 카테고리의 다른 글
회전하는 큐 (feat. 백준, 1021번) (0) | 2022.08.13 |
---|---|
덱 (feat. 백준, 10866번) (0) | 2022.08.13 |
요세푸스 문제 0 (feat. 백준, 11866번) (0) | 2022.08.12 |
카드2 (feat. 백준, 2164번) (0) | 2022.08.12 |
큐 2 (feat. 백준, 18258번) (0) | 2022.08.12 |
Comments