백준 1966 프린터 큐 C++
- C
- 2023. 4. 10.
백준 1966 프린터 큐
백준 1966번 "프린터 큐" 문제의 자세한 내용은 글 하단의 문제 링크를 참고하세요.
1966번 문제에 주어지는 입력 및 예시
입력:
3
1 0
5
4 2
1 2 3 4
6 0
1 1 9 1 1 1
출력:
1
2
5
코드
백준 1966번 "프린터 큐" 문제의 코드입니다.
//1966
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int _testCase,n,_imp,cnt,k,v;
cin>>_testCase;
for(int t=0;t<_testCase;t++){
cnt=0;
cin>>n>>_imp;
queue<pair<int,int>> q;
priority_queue<int> pq; //우선순위 큐.
for(int i=0;i<n;i++){
int tmp;
cin>>tmp;
pq.push(tmp);
q.push({i,tmp});
}
while(!q.empty()){
tie(k,v)=q.front();//first,second
q.pop();
if(pq.top()==v){
pq.pop();
cnt++;
if(k==_imp){
cout<<cnt<<"\n";
break;
}
}
else q.push({k,v});
}
}
return 0;
}
실행
위의 코드를 예제의 입력을 넣어 실행했을 때의 결과입니다.
'C' 카테고리의 다른 글
백준 10828 스택 C++ (0) | 2023.04.11 |
---|---|
백준 10845 큐 C++ (0) | 2023.04.11 |
백준 2583 영역 구하기 C++ (0) | 2023.04.10 |
백준 2468 안전 영역 C++ (0) | 2023.04.10 |
백준 1181 단어 정렬 C++ (0) | 2023.04.07 |