HDU-1873-waiting for medical treatment

Source: Internet
Author: User

Question Link

Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1873

Priority queue, set three priority -- queue

Save doctor1 doctor2 doctor3;

Code

# Include <iostream>
# Include <cstdio>
# Include <cstring>
# Include <queue>
Using namespace STD;

Struct patient
{
Int priority;
Int key;
Friend bool operator <(patient P1, patient P2)
{
If (p1.priority! = P2.priority)
Return p1.priority <p2.priority;

Return p1.key> p2.key;
}
};


Int main (void)
{
Int I, N, K;
Char type [4];
Int patientid, doctorid;
Patient patient [2001];
While (scanf ("% d", & n) = 1)
{
Priority_queue <patient> doctor1;
Priority_queue <patient> doctor2;
Priority_queue <patient> doctor3;
K = 1;
While (n --)
{
Scanf ("% s", type );
If (strcmp (type, "in") = 0)
{
Patient [K]. Key = K;
Scanf ("% d", & doctorid, & patient [K]. Priority );
If (doctorid = 1)
{
Doctor1.push (patient [k]);
}
Else if (doctorid = 2)
{
Doctor2.push (patient [k]);
}
Else
{
Doctor3.push (patient [k]);
}
K ++;
}
Else if (strcmp (type, "out") = 0)
{
Scanf ("% d", & doctorid );
If (doctorid = 1)
{
If (doctor1.empty ())
Printf ("Empty \ n ");
Else
{
Printf ("% d \ n", doctor1.top (). Key );
Doctor1.pop ();
}
}
Else if (doctorid = 2)
{
If (doctor2.empty ())
Printf ("Empty \ n ");
Else
{
Printf ("% d \ n", doctor2.top (). Key );
Doctor2.pop ();
}
}
Else
{
If (doctor3.empty ())
Printf ("Empty \ n ");
Else
{
Printf ("% d \ n", doctor3.top (). Key );;
Doctor3.pop ();
}
}
}
}
}
Return 0;
}

HDU-1873-waiting for medical treatment

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.