Question: uva10588-queuing at the doctors (priority queue)
Employee health check: there are a total of M doctors, each doctor receives an employee every second, and each employee has an inspection list. The inspection order above is strictly enforced, check the time when the last employee leaves the clinic.
Solution: queue simulation. The priority queue is used to store the guest list of each office and record the time and serial number. If the time is the same as the serial number, priority is given. Otherwise, priority is given to the earlier time. Then, give the current time now, the first guest in front of the ward before this time will undergo a health check first, and then put the guest in the queue of the next office he wants to go. When no guests are in the ward, output the last now.
Code:
# Include <cstdio> # include <queue> # include <cstring> using namespace STD; const int n = 1005; const int INF = 1e6 + 5; typedef long ll; struct person {int th; ll t; person () {} person (INT th, ll T): Th (th), T (t) {} bool operator <(const person & A) const {return T>. T | (t =. T & th>. th) ;}}; priority_queue <person> q [N]; // The Office waits for the queue of the employee <int> P [N]; // check list of employees ll T [N]; int main () {int t; int n, m, K, item; int P; ll now; scanf ("% d", & T); While (t --) {scanf ("% d", & N, & M); now = inf; For (INT I = 0; I <n; I ++) {scanf ("% LLD % d", & T [I], & K); now = min (now, t [I]); While (k --) {scanf ("% d", & item); P [I]. push (item) ;}}for (INT I = 0; I <n; I ++) {If (! P [I]. empty () {P = P [I]. front (); P [I]. pop (); Q [p]. push (person (I, T [I]);} person; while (1) {for (INT I = 1; I <= m; I ++) {If (! Q [I]. Empty () {person = Q [I]. Top (); If (person. T> now) continue; If (! P [person. th]. empty () {P = P [person. th]. front (); P [person. th]. pop (); Q [p]. push (person. th, now + 1);} Q [I]. pop () ;}// printf ("% LLD \ n", now); LL min_n = inf; For (INT I = 1; I <= m; I ++) {If (! Q [I]. Empty () min_n = min (min_n, Q [I]. Top (). T) ;}now ++; If (min_n! = Inf) Now = max (now, min_n); elsebreak;} printf ("% LLD \ n", now);} return 0 ;}
Uva10588-queuing at the doctors (priority queue)