HDU 1509 Windows Message Queue

Source: Internet
Author: User

Water problem, used to familiarize with the priority queue.


There are two keys, one is priority, the other is ID. Prioritize by priority and rank by ID.


#include <cstdio> #include <cstring> #include <string> #include <queue> #include <algorithm > #include <map> #include <stack> #include <iostream> #include <list> #include <set># include<vector> #include <cmath> #define INF 0x7fffffff#define EPS 1e-8#define LL long long#define PI 3.141592654#define CLR (A, B) memset (A,b,sizeof (a)) #define for (I,A,B) for (int. i=a;i<b;i++) #define FOR0 (i,a,b) for ( int i=a;i>=b;i--) #define PB push_back#define Debug puts ("==fuck==") #define Acfun Std::ios::sync_with_stdio (FALSE) #    Define SIZE 20+10using namespace std;struct lx{Char str[101];    int s;    int value;    int ID;        friend bool operator < (LX A,lx b) {if (A.value==b.value) return a.id>b.id;    Return a.value>b.value;    }};int Main () {priority_queue<lx> PQ;    Char head[11];    int id=0;              while (scanf ("%s", head)!=eof) {if (strcmp (head, "GET") ==0) {if (Pq.empty ())  Puts ("EMPTY queue!");                else {LX now;                Now=pq.top ();                Pq.pop ();            printf ("%s%d\n", NOW.STR,NOW.S);            }} else if (strcmp (head, "PUT") ==0) {LX now;            scanf ("%s%d%d", Now.str,&now.s,&now.value);            now.id=id++;        Pq.push (now); }    }}


HDU 1509 Windows Message 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.