首页 > 其他 > 详细

hdu1873优先队列

时间:2015-06-07 17:22:58      阅读:211      评论:0      收藏:0      [点我收藏+]
 1 #include<stdio.h>
 2 #include<queue>
 3 using namespace std;
 4 struct node
 5 {
 6     int id;
 7     int val;
 8     friend bool operator< (node a,node b)
 9     {
10         if(a.val!=b.val)
11         return a.val<b.val;
12         else
13         {
14             return a.id>b.id;
15         }
16     }
17 };
18 int n;
19 int main()
20 {
21     int i,j;
22     char s[100];
23     int num,set;
24     while(scanf("%d",&n)!=EOF)
25     {
26         num=1;
27         node temp;
28         priority_queue<node>q[5];
29         for(i=1;i<=n;i++)
30         {
31             scanf("%s",s);
32             if(s[0]==I)
33             {
34                 scanf("%d %d",&set,&temp.val);
35                 temp.id=num++;
36                 q[set].push(temp);
37             }
38             else
39             {
40                 scanf("%d",&set);
41                 if(q[set].empty())
42                 {
43                     printf("EMPTY\n");
44                     continue;
45                 }
46                 node exm=q[set].top();
47                 q[set].pop();
48                 printf("%d\n",exm.id);
49             }
50         }
51     }
52 }

 

hdu1873优先队列

原文:http://www.cnblogs.com/sweat123/p/4558654.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!