题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=1873
运用优先队列写就行了
1 #include<stdio.h> 2 #include<iostream> 3 #include<string.h> 4 #include<queue> 5 #define N 2100 6 using namespace std; 7 8 struct node 9 { 10 int ID,B; 11 friend bool operator < (node n1,node n2) 12 { 13 if(n1.B != n2.B) 14 return n1.B < n2.B; 15 return n1.ID >n2.ID; 16 } 17 }; 18 19 int main() 20 { 21 int n,i,m,x,y; 22 char str[30],ch,s[N]; 23 node a,z; 24 25 while(scanf("%d",&n)!=EOF) 26 { 27 priority_queue<node>q[4];//如果定义在上面要记得清零; 28 m=0; 29 for(i=1;i<=n;i++) 30 { 31 scanf("%s",str); 32 scanf("%c",&ch); 33 if(strcmp(str,"IN")==0) 34 { 35 m++; 36 gets(s); 37 sscanf(s,"%d %d",&x,&y); 38 a.ID=m; 39 a.B=y; 40 41 q[x].push(a); 42 43 } 44 else 45 { 46 scanf("%d",&x); 47 if(!q[x].empty()) 48 { 49 z=q[x].top(); 50 printf("%d ",z.ID); 51 q[x].pop(); 52 } 53 else 54 printf("EMPTY "); 55 } 56 } 57 } 58 return 0; 59 }