UVA 12100 Printer Queue (Queue and priority queues, water)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.