Sicily 1443. printer queue operation

Source: Internet
Author: User

The question is the element of the maximum priority in the queue. If the first line is not the maximum permission, put it at the end of the team. The question requires a given position to calculate the departure time.

Use an array to save the maximum permissions and then sort them. Check whether the first element of the team has the same permissions as the corresponding position of the array. If the permissions are the same, the team leaves the team. Otherwise, the team is placed at the end of the team.

 

 # include 
  
    # include 
   
     # include 
    
      using namespace STD; struct job {int priority; int number; job (INT priority, int number) {This-> priority = priority; this-> Number = Number ;}job () {}}; bool CMP (int, Int B) {return A> B;} int main () {queue 
     
       q; int B [101]; INT cases; int n, m; int, count, result; job TMP; CIN> cases; while (cases --) {COUNT = 0; Result = 0; CIN> N> m; for (INT I = 0; I 
      
        A; B [I] = A; q. push (JOB (A, I);} Sort (B, B + N, CMP); While (1) {If (Q. front (). priority! = B [count]) {TMP = Q. front (); q. pop (); q. push (TMP);} else {result ++; count ++; If (Q. front (). number = m) break; q. pop () ;}} cout 
       
      
     
    
   
  
Related Article

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.