1 //#include <bits/stdc++.h>2#include <cstdio>3#include <queue>4#include <algorithm>5 using namespacestd;6typedefLong Longll;7 /**8 Test instructions: All tasks in the queue, if the currently printed task priority is not the largest, then move to the tail of the queue. Ask when the task labeled K is printed at what time;9 idea: Prioritize whether the highest priority is determined by the priority queue. To simulate a task with a queueTen (1) If the task in front of the queue is not the highest priority One task moves to the end A Subscript k--(if k = 0, k = queue.size ()-1) - (2) If the person in front of the queue is the highest priority - print tasks. the if subscript k = = 0 Output Answer - if k!=0 k-1, time++; - - */ + intN,index; - + voidsolve () { A intAns =1; atpriority_queue<int>PQ; -queue<int>que; - for(inti =0; I < n; i + +){ - inttmp; -scanf"%d",&tmp); - Que.push (TMP); in Pq.push (TMP); - } to for(;;) { + if(Que.front () = =Pq.top ()) { - if(Index = =0){ theprintf"%d\n", ans); * Break; $}Else{Panax Notoginseng Que.pop (); - Pq.pop (); theIndex--; + } AAns + +; the}Else{ + intTMP =Que.front (); - Que.pop (); $ Que.push (TMP); $ if(Index = =0) index = Que.size ()-1; - ElseIndex--; - } the } - }Wuyi the intMain () { - Wu intT; -scanf"%d",&T); About while(t--){ $scanf"%d%d",&n,&index); - solve (); - } - return 0; A}
UVA 12100 Printer Queue (Queue and priority queues, water)