Portal: Https://uva.onlinejudge.org/external/121/12100.pdf
Test instructions: The task to be printed in the queue (1 <= n <= 100) with priority (1-9), the print step for each time from the first team to take one, if there is no priority in the queue than the task, print this task; If there is a high priority, put this task at the end of the queue and print the highest priority. It takes 1 minutes per print time to find out when a given task is printed.
Water problem A half-day is a weak slag .....
The worst-case scenario requires MAXN*MAXN space ...
Front rear record before and after position
1#include <bits/stdc++.h>2 using namespacestd;3 4 Const intMAXN =111;5 intt, N, M, _time;6 intque[maxn*MAXN];7 8 voidprocess () {9 intFront =0, rear =N;Ten while(true){ One intMaxi =Que[front]; A for(inti = front; I < rear; ++i) { - if(Que[i] >Maxi) { - if(front = = m) m =Rear; theque[rear++] = que[front++]; - Break; - } - Else if(i = = Rear-1){ +++_time; - if(front = = m)return ; +front++; A } at } - } - } - intMain () { -CIN >>T; - while(t--){ in_time =0; -CIN >> N >>m; to for(inti =0; I < n; ++i) Cin >>Que[i]; + process (); -cout << _time <<Endl; the } * return 0; $}
UVa 12100 Printer Queue (exercise 5-7)