hdu1873- doctor to line up - (priority queue structure)

http://acm.hdu.edu.cn/showproblem.php?pid=1873

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<math.h>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include<set>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;

struct patient
{
    int id;
    int val;
};

patient p[2005];

bool operator< (Patient P1, P2 Patient) 
{ 
    IF (p1.val == p2.val)
         return p1.id> p2.id;
     return p1.val < p2.val; 
} 
/// higher priority top surface, overload operator-defined functions and out the opposite effect 
The priority_queue <Patient> que1, que2, que3; 


int n-;
 String S;
 int A, B; 


int main () 
{ 
    the while (CIN >> n-) 
    { 
        the while (que1.size ()) 
            que1.pop (); 
        the while (que2.size ()) 
            que2.pop (); 
        the while (que3.size ()) 
            que3.pop ();
        int CNT = 0 ;
         the while (N-- ) 
        { 
            CIN >> S;
             IF (S [ 0 ] == ' the I ' ) 
            { 
                CIN >> A >> b; /// have a priority to the patient b Diagnosis and treatment of a physician 
                CNT ++ ;
                 IF (a == . 1 ) /// thrown give doctors a queue 
                    que1.push ({CNT, B});
                 IF (a == 2 ) 
                    que2.push ({CNT, B}); 
                IF (A == . 3) 
                    Que3.push ({cnt, b}); 
            } 
            the else 
            { 
                cin >> a; /// doctors a diagnosis of a patient, ask the person number, that team is listed team 
                Patient now;
                 IF (a == 1 ) 
                { 
                    IF (que1.size ()) 
                    { 
                        now = que1.top (); 
                        que1.pop (); 
                        COUT << now.id << endl; 
                    } 
                    the else 
                        COUT << " EMPTY " <<endl;
                }
                else if(a==2)
                {
                    if(que2.size())
                    {
                        now=que2.top();
                        que2.pop();
                        cout<<now.id<<endl;
                    }
                    else
                        cout<<"EMPTY"<<endl;
                }
                else
                {
                    if(que3.size())
                    {
                        now=que3.top();
                        que3.pop();
                        cout<<now.id<<endl;
                    }
                    else
                        cout<<"EMPTY"<<endl;
                }
            }

        }
    }
    return 0;
}
hdu1873

 

Guess you like

Origin www.cnblogs.com/shoulinniao/p/11372851.html