LA 3135 (优先队列) Argus

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

 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 }

代码君

时间: 2025-01-05 18:10:08

LA 3135 (优先队列) Argus的相关文章

la 3135 Argus Data Structure

// la 3135 Argus // 学习一下优先队列的使用吧,题目还是比较简单的 // 刘老师的训练指南p188. // 继续练吧.... #include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cfloat> #include <climits> #include <cmath> #include &l

(算法竞赛入门经典 优先队列)LA 3135(前K条指令)

A data stream is a real-time, continuous, ordered sequence of items. Some examples include sensor data, Internet traffic, financial tickers, on-line auctions, and transaction logs such as Web usage logs and telephone call records. Likewise, queries o

LA 3135

Argus Time limit: 3.000 seconds A data stream is a real-time, continuous, ordered sequence of items. Some examples include sensor data, Internet traffic, financial tickers, on-line auctions, and transaction logs such as Web usage logs and telephone c

LA 3135 Argus (优先队列的简单应用)

A data stream is a real-time, continuous, ordered sequence of items. Some examples include sensordata, Internet traffic, nancial tickers, on-line auctions, and transaction logs such as Web usage logsand telephone call records. Likewise, queries over

LA 3135 Argus (优先队列)

https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1136 #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<queue> using namespace

(算法入门经典大赛 优先级队列)LA 3135(之前K说明)

A data stream is a real-time, continuous, ordered sequence of items. Some examples include sensor data, Internet traffic, financial tickers, on-line auctions, and transaction logs such as Web usage logs and telephone call records. Likewise, queries o

UVALive - 3135 - Argus (优先队列!!)

UVALive - 3135 Argus Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description A data stream is a real-time, continuous, ordered sequence of items. Some examples include sensor data, Internet traffic, financi

【优先队列之多路归并】UVALive 3135 Argus

UVALive 3135 Argus http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18684 题意 编写一个系统执行一系列Register命令:Register Q_num Period,每个命令执行周期是Period,执行事件Q_num:如果事件同时发生,优先执行Q_num小的. 示例 Sample Input Register 2004 200 Register 2005 300 # 5 Sample Output

uva11997 K Smallest Sums&amp;&amp;UVALive 3135 Argus(优先队列,多路归并)

#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<string> #include<cmath> #include<map> #include<set> #include<vector> #include<algorithm> #include<stack> #in