7 IN 1 1 IN 1 2 OUT 1 OUT 2 IN 2 1 OUT 2 OUT 1 2 IN 1 1 OUT 1 Sample Output2 EMPTY 3 1 1重新理解拉优先队列,很水的了
#include<cstdio>#include<queue>#include<stack>#include<algorithm>using namespace std;struct node{ int a, b; friend bool Operator < (node x, node y) { if(x.b == y.b) { return x.a > y.a; } else { return x.b < y.b; } }}; int main(){ int n; while(~scanf("%d",&n)) { char str[10]; node p; int a, b; int k = 1; priority_queue<node> fq_1,fq_2,fq_3; for(int i = 0; i< n; i++) { scanf("%s",str); if(str[0] == 'I') { scanf("%d%d",&a,&b); if(a == 1) { p.a = k; k++; p.b = b; fq_1.push(p); } if(a == 2) { p.a = k; k++; p.b = b; fq_2.push(p); } if(a == 3) { p.a = k; k++; p.b = b; fq_3.push(p); } } else { scanf("%d",&a); if(a == 1) { if(fq_1.empty()) printf("EMPTY/n"); else { printf("%d/n",fq_1.top()); fq_1.pop(); } } if(a == 2) { if(fq_2.empty()) printf("EMPTY/n"); else { printf("%d/n",fq_2.top()); fq_2.pop(); } } if(a == 3) { if(fq_3.empty()) printf("EMPTY/n"); else { printf("%d/n",fq_3.top()); fq_3.pop(); } } } } }}代码很好理解
新闻热点
疑难解答