LA 3135 (优先队列)
来源:互联网 发布:天盾数据恢复官网下载 编辑:程序博客网 时间:2024/05/27 20:09
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 P eriod
Q num (0 < Qnum ≤ 3000) is query ID-number, and P eriod (0 < P eriod ≤ 3000) is the interval
between two consecutive returns of the result. After P eriod seconds of register, the result will be
returned for the first time, and after that, the result will be returned every P eriod 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
这是默认数值大的优先出队
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 P eriod
Q num (0 < Qnum ≤ 3000) is query ID-number, and P eriod (0 < P eriod ≤ 3000) is the interval
between two consecutive returns of the result. After P eriod seconds of register, the result will be
returned for the first time, and after that, the result will be returned every P eriod 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
题意:有一个系统,它每p秒就会产生一个Q的事件,这个系统是优先处理Q值小的,请输出处理顺序
题解:开始对于每p秒就会产生一个Q的事件这个问题不知道怎么处理,想着每次都遍历一遍事件,然后定义一个变量计时之类的。。。。。。,看了书上的才发现根本没有这么复杂,只要加上自己的生成周期重新压回优先队列,定义队列p小的先出对,否则Q小的先出队就可以了,然后直接使用优先队列就可了
这里定义的优先队列是
priority_queue<int>pq;
这是默认数值大的优先出队
AC代码:
#include<iostream>#include<cstdio>#include<vector>#include<string>#include<algorithm>#include<queue>using namespace std;#define N 100005struct point{int qm,pr;int orgin;point(int _O,int _Q,int _P):orgin(_O),qm(_Q),pr(_P){}point(){}bool operator <(const point &x1)const{return(this->qm>x1.qm||this->qm==x1.qm&&this->pr>x1.pr); }};priority_queue<point>pq;int main(){#ifdef CDZSCfreopen("i.txt","r",stdin);#endifstring s;int q,p;while(cin>>s&&s!="#"){scanf("%d%d",&p,&q);pq.push(point(q,q,p));}int k;scanf("%d",&k);while(k--){point tmp=pq.top();printf("%d\n",tmp.pr);pq.pop();tmp.qm+=tmp.orgin;pq.push(tmp);}return 0;}
0 0
- LA 3135 优先队列
- LA 3135 (优先队列)
- LA 3135 argus(优先队列)
- LA 3135 Argus 优先队列
- LA 3135 Argus ( 优先队列 )
- 蓝书 LA 3135 优先队列入门
- 优先队列 阿格斯(Argus Beijing La 3135)
- LA 4254 Processor(二分+贪心+优先队列)
- LA 3135 Argus (2004北京 模拟系统调度 优先队列实现)
- (算法竞赛入门经典 优先队列)LA 3135(前K条指令)
- UVA-LA 3135 2004年北京站C题 STL priority_queue自定义优先顺序优先队列的使用
- 优先队列(UVAL-3135)
- UVALive - 3135 Argus 优先队列
- UVALive - 3135 Argus 优先队列
- UVALive - 3135 Argus【优先队列】
- 优先队列
- 优先队列
- 优先队列
- Kerberos+Java连接Hbase
- JPA之Entity注解说明
- [AngularJS] Simple Data Binding
- 绑定数据时。在后台给GridView添加事件
- 设计模式C++实现--中介者模式
- LA 3135 (优先队列)
- iOS判断字符串是否包含空格
- 第八章------拦截器机制
- JAVA HashMap详细介绍和示例
- POJ1159 Palindrome 动态规划+滚动数组
- 设计模式C++实现--职责链模式
- 浅谈 Java Serializable 系列化 反系列化
- bzoj3611: [Heoi2014]大工程
- Java数据结构和算法系列1--链表