#include<iostream> #include<queue> #include<algorithm> using namespace std; struct Node{ int order; int pri; bool operator < (const Node b) const{ return pri < b.pri; } }; int main() { int T; cin >> T; while(T--) { int n, m; cin >> n >>m; queue<Node> q; priority_queue<Node> pq; Node x; for (int i = 0; i < n; i++) { cin >> x.pri; x.order = i; q.push(x); pq.push(x); } int cnt = 0; while(true) { if(pq.top().pri == q.front().pri) { cnt++; x = q.front(); pq.pop(); q.pop(); if(x.order == m) break; } else{ q.push(q.front()); q.pop(); } } cout << cnt <<endl; } }
UVA - 12100 Printer Queue【优先队列+队列】
猜你喜欢
转载自blog.csdn.net/qq_37602930/article/details/80081187
今日推荐
周排行