標籤:include using als cstring cpp long ace operator name
水題。用來熟悉優先隊列。
有兩個鍵,一個是優先順序。一個是ID。按優先順序排。優先順序一樣就按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