博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Argus
阅读量:6785 次
发布时间:2019-06-26

本文共 3889 字,大约阅读时间需要 12 分钟。

http://poj.org/problem?id=2051

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 200Register 2005 300#5

Sample Output

20042005200420042005 经常用堆来实现优先队列,堆培训如下
1 #include"iostream" 2 #include"cstdio" 3 #include"cstring" 4 #include"string" 5 using namespace std; 6 struct abc 7 { 8     int time; 9     int id;10     int t;11 } a[3003];12 //int len;13 int k;14 void down(abc *a,int p,int len)15 {16     abc r=a[p];17     int i;18     for(i=p*2;i<=len;i*=2)19     {20         if(i
a[i+1].time)23 i++;24 else if(a[i].time==a[i+1].time&&a[i].id>a[i+1].id)25 i++; 26 }27 if(r.time
0;i--)38 down(a,i,len);39 return ; 40 }41 int main()42 {43 string str;44 int i=1;45 cin>>str;46 while(str.compare("#")!=0)47 {48 cin>>a[i].id>>a[i].t;49 a[i].time=a[i].t;50 i++;51 cin>>str;52 }53 cin>>k;54 int len=i-1;55 build(a,len);56 for(i=1;i<=k;i++)57 {58 cout<
<
View Code

用优先队列,STL解很简单,更具竞争力

#include"iostream"#include"queue"#include"string"using namespace std;struct abc{    int time;    int id;    int t;    bool operator<(const abc &a) const    {        if(time==a.time)           return id>a.id;        else           return time>a.time;          }} ;int main(){    priority_queue
p; abc a; string str; int k; cin>>str; while(str.compare("#")!=false) { cin>>a.id>>a.t; a.time=a.t; p.push(a); cin>>str; } cin>>k; for(int i=1;i<=k;i++) { a=p.top(); a.time+=a.t; cout<
<

 

转载于:https://www.cnblogs.com/767355675hutaishi/p/3762335.html

你可能感兴趣的文章
bash 函数使用,实现模块化编程
查看>>
LVS实现负载均衡
查看>>
LAMP架构下安装Discuz!论坛
查看>>
shell
查看>>
正则表达式
查看>>
我的友情链接
查看>>
spring MVC的第一次记录
查看>>
js获取 X-X-X N 天后 是 X年X月X日
查看>>
我的友情链接
查看>>
神奇的504 Bad Gateway Timeout
查看>>
mysql安装报错解决一例
查看>>
在服务器上排除问题的头五分钟
查看>>
安装 - FreeBSD + Nginx 环境搭建教程(推荐)
查看>>
学习cocos2d --- 场景创建
查看>>
小凡带你搭建本地的光盘yum源
查看>>
java 求最大公约数和最小公倍数
查看>>
vmware workstation的bridged NAT host-only区别与适用场景简介
查看>>
Linux基础知识
查看>>
Struts2中的OGNL详解
查看>>
隐藏/屏蔽服务器信息与web软件版本信息
查看>>