【暑假】[实用数据结构]UVAlive 3135 Argus
UVAlive 3135 Argus
Time Limit: 3000MS | Memory Limit: Unknown | 64bit IO Format: %lld & %llu |
Description

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 over streams run continuously over a period of time and incrementally return new results as new data arrives. For example, a temperature detection system of a factory warehouse may run queries like the following.
Query-1: �Every five minutes, retrieve the maximum temperature over the past five minutes.� Query-2: �Return the average temperature measured on each floor over the past 10 minutes.�
We have developed a Data Stream Management System called Argus, which processes the queries over the data streams. Users can register queries to the Argus. Argus will keep the queries running over the changing data and return the results to the corresponding user with the desired frequency.
For the Argus, we use the following instruction to register a query:
Register Q_num Period
Q_num (0 < Q_num ≤ 3000) is query ID-number, and Period (0 < Period ≤ 3000) is the interval between two consecutive returns of the result. After Period seconds of register, the result will be returned for the first time, and after that, the result will be returned every Period seconds.
Here we have several different queries registered in Argus at once. It is confirmed that all the queries have different Q_num. Your task is to tell the first K queries to return the results. If two or more queries are to return the results at the same time, they will return the results one by one in the ascending order of Q_num.
Input
The first part of the input are the register instructions to Argus, one instruction per line. You can assume the number of the instructions will not exceed 1000, and all these instructions are executed at the same time. This part is ended with a line of �#�.
The second part is your task. This part contains only one line, which is one positive integer K (≤ 10000).
Output
You should output the Q_num of the first K queries to return the results, one number per line.
Sample Input
Register 2004 200
Register 2005 300
#
5
Sample Output
2004
2005
2004
2004
2005 -------------------------------------------------------------------------------------------------------------------------------------------------------- 思路:
优先队列模拟。时间小的优先级高,每次选取time最小的出队记录Qnum后修改time重新入队(意味着该任务进入下一轮)
注意:优先队列中重载运算符比较特殊,我这样理解:STL中默认priority_queue为大根堆,而我们所需要的是小根堆,因此将 < 重载为相反符号。 代码:
//处理器模拟
#include<cstdio>
#include<queue>
#define FOR(a,b,c) for(int a=(b);a<(c);a++)
using namespace std; struct Node{
int qnum,period,time;
bool operator < (const Node& rhs) const{
return time>rhs.time || (time==rhs.time && qnum>rhs.qnum);
}
};
//优先队列默认为大根堆,而需要的是“小根堆 ”因此相反地定义 < int main(){
priority_queue<Node> Q;
char s[];
Node x; while(scanf("%s",s) && s[] != '#'){
scanf("%d%d",&x.qnum,&x.period);
x.time=x.period; //time_init
Q.push(x);
}
int k; scanf("%d",&k);
while(k--){
x=Q.top(); Q.pop();
printf("%d\n",x.qnum);
x.time += x.period; //更改为下一轮的时间重新放回优先队列
Q.push(x);
}
return ;
}
【暑假】[实用数据结构]UVAlive 3135 Argus的更多相关文章
- uva11997 K Smallest Sums&&UVALive 3135 Argus(优先队列,多路归并)
#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #inc ...
- 【暑假】[实用数据结构]UVAlive 3026 Period
UVAlive 3026 Period 题目: Period Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld ...
- 【暑假】[实用数据结构]UVAlive 3942 Remember the Word
UVAlive 3942 Remember the Word 题目: Remember the Word Time Limit: 3000MS Memory Limit: Unknown ...
- 【暑假】[实用数据结构]UVAlive 4329 Ping pong
UVAlive 4329 Ping pong 题目: Ping pong Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: % ...
- 【暑假】[实用数据结构]UVAlive 3027 Corporative Network
UVAlive 3027 Corporative Network 题目: Corporative Network Time Limit: 3000MS Memory Limit: 30000K ...
- 【暑假】[实用数据结构]UVAlive 3644 X-Plosives
UVAlive X-Plosives 思路: “如果车上存在k个简单化合物,正好包含k种元素,那么他们将组成一个易爆的混合物” 如果将(a,b)看作一条边那么题意就是不能出现环,很容易联想到K ...
- 【暑假】[实用数据结构]UVAlive 4670 Dominating Patterns
UVAlive 4670 Dominating Patterns 题目: Dominating Patterns Time Limit: 3000MS Memory Limit: Unkn ...
- uvalive 3135 Argus priority_queue
用优先队列维护每个时间点优先级最高的元素. #include<iostream> #include<cstdio> #include<cstdlib> #inclu ...
- uvalive 3135 Argus
https://vjudge.net/problem/UVALive-3135 题意: 有一个系统有多个指令,每个指令产生一个编号为qnum的时间,每个指令的触发间隔不相同,现在给出若干个指令,现在的 ...
随机推荐
- chm文件访问提示:已取消到该网页的导航
chm文件访问提示:已取消到该网页的导航或不能链接网页 解决方案: 右击chm文件,选择:属性->解除锁定 ,再重新打开文件即可
- 使用List,Dictionary加载数据库中的数据
情景描述:数据库中有一张设备表,字段DWDM存放的是各个厂编号,字段ZNBH存放的是设备编号.其中DWDM跟ZNBH是一对多的关系.需要将数据库中的值加载到List<Dictionary< ...
- Git教程之时光穿梭(3)
我们已经成功地添加并提交了一个readme.txt文件,现在我们继续修改readme.txt文件,改成如下内容:
- C++:常类型Const
常类型:使用类型修饰符const说明的类型,常类型的变量或对象成员的值在程序运行期间是不可改变的. 3.10.1 常引用 如果在说明引用时用const修饰,则被说明的引用为常引用.如果用常引用做形参, ...
- 内存泄露了么: Handlers & Inner Classes
看到一篇关于handler和匿名类关于内存泄露的文章,觉得不错,充分发挥拿来主义,先放这儿看着! From:http://www.androiddesignpatterns.com/2013/01/i ...
- VC 6.0 LNK2005 错误 处理
造成LNK2005错误主要有以下几种情况: 1.重复定义全局变量.可能存在两种情况: A.对于一些初学编程的程序员,有时候会以为需要使用全局变量的地方就可以使用定义申明一下.其实这是错误的,全局变量是 ...
- firebug的使用方法和技巧(web开发调试工具)
Firebug是firefox下的一个插件,能够调试所有网站语言,如Html,Css等,但FireBug最吸引我的就是javascript调试功 能,使用起来非常方便,而且在各种浏览器下都能使用(IE ...
- [POJ3279]Fliptile(开关问题,枚举)
题目链接:http://poj.org/problem?id=3279 题解:http://www.cnblogs.com/helenawang/p/5538547.html /* ━━━━━┒ギリギ ...
- Android中ProgressDialog的简单示例
网上一般对进度条的示例都是如何显示,没有在任务结束如何关闭的文章,参考其他文章经过试验之后把整套进度条显示的简单示例如下: 建立android工程等工作都略去,Google一下就可以了. 下面来介绍主 ...
- Qt之自定义界面(添加自定义标题栏)
简述 通过上节内容,我们实现了自定义窗体的移动,但是我们缺少一个标题栏来显示窗体的图标.标题,以及控制窗体最小化.最大化.关闭的按钮. 自定义标题栏后,所有的控件我们都可以定制,比如:在标题栏中添加换 ...