首页 > 其他 > 详细

LA 3135 (优先队列) Argus

时间:2015-03-15 21:13:13      阅读:254      评论:0      收藏:0      [点我收藏+]

将多个有序表合并成一个有序表就是多路归并问题,可用优先队列来解决。

技术分享
 1 #include <cstdio>
 2 #include <queue>
 3 using namespace std;
 4 
 5 const int maxn = 1000 + 10;
 6 
 7 struct Node
 8 {
 9     int time, period, num;
10     bool operator < (const Node& rhs) const
11     {
12         return time > rhs.time || (time == rhs.time && num > rhs.num);
13     }
14 }a[maxn];
15 
16 char s[100];
17 
18 int main()
19 {
20     //freopen("in.txt", "r", stdin);
21 
22     priority_queue<Node> Q;
23     while(scanf("%s", s) == 1 && s[0] != #)
24     {
25         Node t;
26         scanf("%d%d", &t.num, &t.period);
27         t.time = t.period;
28         Q.push(t);
29     }
30     int k;
31     scanf("%d", &k);
32     while(k--)
33     {
34         Node t = Q.top(); Q.pop();
35         printf("%d\n", t.num);
36         t.time += t.period;
37         Q.push(t);
38     }
39 
40     return 0;
41 }
代码君

 

LA 3135 (优先队列) Argus

原文:http://www.cnblogs.com/AOQNRMGYXLMV/p/4340289.html

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