Uva10588-queuing at the doctors (priority queue)

Source: Internet
Author: User

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)

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.