uva 1203 - Argus

简单的优先队列的应用;

代码:

 1 #include<queue>
 2 #include<cstdio>
 3 using namespace std;
 4 
 5 struct node
 6 {
 7     int num;
 8     int ti;
 9     int period;
10     bool operator<(const node &t)const
11     {
12         if(ti==t.ti)return num>t.num;
13         return ti>t.ti;
14     }
15 };
16 priority_queue< node >q;
17 char s[20];
18 int main()
19 {
20     int m;
21     node a;
22     while(scanf("%s",&s)&&s[0]!='#')
23     {
24         scanf("%d%d",&a.num,&a.period);
25         a.ti=a.period;
26         q.push(a);
27     }
28     scanf("%d",&m);
29     while(m--)
30     {
31         node k=q.top();
32         q.pop();
33         printf("%d\n",k.num);
34         k.ti+=k.period;
35         q.push(k);
36     }
37     return 0;
38 }
View Code

 

posted @ 2013-10-24 09:49  Yours1103  阅读(153)  评论(0编辑  收藏  举报