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