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