Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 16582 Accepted Submission(s): 7005node
7 IN 1 1 IN 1 2 OUT 1 OUT 2 IN 2 1 OUT 2 OUT 1 2 IN 1 1 OUT 1
很明顯的優先隊列 開一個隊列的數組來模擬就行了c++
#include<bits/stdc++.h> using namespace std; typedef struct node { int id; int level; friend bool operator < (const node &a,const node b) { return a.level<b.level||(a.level==b.level&&a.id>b.id); } }person; int n; int main() { while(scanf("%d",&n)!=EOF) { int k=1,x,y; priority_queue<person>q[4]; while(n--) { char str[10]; scanf("%s %d",str,&x); if(strcmp(str,"IN")==0) { scanf("%d",&y); person newone; newone.id=k; newone.level=y; q[x].push(newone); k++; } else { if(q[x].empty()) cout<<"EMPTY"<<endl; else { cout<<q[x].top().id<<endl; q[x].pop(); } } } } }