HDU 1509 WINDOWS Message Queue

Source: Internet
Author: User

Obvious priority queue

I used STL, but I don't fully understand it. I can write a heap estimate myself. I can use it if I have a tool!

 # Include  <  Iostream  >  
# Include < Queue >
# Include < Vector >
# Include < Stdio. h >

Using Namespace STD;
Const Int Maxn = 60001 ;

Struct Message
{
Char Name [ 20 ];
Int Para, PRI;
Int Order;
Bool Operator < ( Const Message & M1) Const
{
If (PRI = M1.pri)
Return Order > M1.order;
Return PRI < M1.pri;
}
};

Struct CMP
{
Bool Operator ()( Const Message & M1, Const Message & M2 ){
If (M1.pri = M2.pri)
Return M1.order > M2.order;
Return M1.pri > M2.pri;
}
};
// I don't understand the above. I tried it all. c ++ STL has no time to read it!
Priority_queue < Message, Vector < Message > , CMP > Q;

Int Main (){
Char STR [ 5 ], Name [ 20 ];
Int Para, PRI, CNT = 1 ;
While (Scanf ( " % S " , STR) = 1 ){
Switch (STR [ 0 ])
{
Case ' G ' :
If (Q. Empty ())
Printf ( " Empty queue! \ N " );
Else {
Message MOUT = Q. Top ();
Q. Pop ();
Printf ( " % S % d \ n " , MOUT. Name, MOUT. Para );
}
Break ;
Case ' P ' :
Scanf ( " % S % d " , Name, & Para, & PRI );
Message m;
Strcpy (M. Name, name );
M. Para = Para;
M. PRI = PRI;
M. Order = CNT ++ ;
Q. Push (m );
Break ;
}

}
Return 0 ;< BR >}
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.