poj 2051 Argus

题目链接:

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

Source

 
思路就是把此次出队列的数据的出现的时间值加上它的周期,得到下次出现的时间,然后按这个时间的数据值加入大优先队列中。
 
代码:
poj 2051 Argus
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<queue>
 4 #include<string>
 5 
 6 using namespace std;
 7 
 8 struct node
 9 {
10     friend bool operator<(node n1,node n2)
11     {
12         if(n1.time==n2.time) return n1.ID>n2.ID;   //如果时间相同则按,ID号从小到大
13         return n1.time>n2.time;   //优先级按秒数从小到大
14     }
15     int ID;
16     int Period;
17     int time;
18 };
19 
20 
21 int main()
22 {
23     char s[20];
24     int ID,Period,T;
25     int i;
26     node temp;
27     priority_queue<node> qn;  //声明一个优先队列
28     while(scanf("%s",s))
29     {
30         if(s[0]==#) break;
31         scanf("%d%d",&ID,&Period);
32         temp.ID=ID;
33         temp.Period=Period;
34         temp.time=Period;
35         qn.push(temp);    //入队列
36     }
37     scanf("%d",&T);
38     while(T--)
39     {
40         temp=qn.top();    //把队列头部的数据赋值给temp
41         qn.pop();         //出队列
42         temp.time+=temp.Period;   //计算下次出现此ID号的秒数
43         qn.push(temp);            //把得到的新数据加入队列
44         printf("%d\n",temp.ID);
45     }
46     return 0;
47 }
poj 2051 Argus

 

poj 2051 Argus

上一篇:2013年全年目标及执行情况跟踪


下一篇:分析了thoughtworks三期的技术雷达