Priority queue (UVAL-3135)

Source: Internet
Author: User

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.

The second part is your task. This part contains only one line, which is one positive integer k (≤ 10000 ).

Output

You shoshould 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
 
 
The question is probably like this,
Rigister num period
Each period generates a num event.
Let you find the number of the first K times. Classic priority queue maintenance.
 
Paste the Code:
#include <stdio.h>#include <string.h>#include <iostream>#include <string>#include <queue>using namespace std;struct node{int num;int period;int time;bool operator < (const node& t) const{if (time != t.time){return time > t.time;}else{return num > t.num;}}}t;priority_queue <node> Q;void init(){while (!Q.empty()){Q.pop();}}int main(){char str[22];init();while (scanf("%s", str) == 1){if (str[0] == '#'){break;}scanf("%d%d", &t.num, &t.period);t.time = t.period;Q.push(t);}int k;scanf("%d", &k);for (int i = 0; i < k; i++){t = Q.top();Q.pop();printf("%d\n", t.num);t.time += t.period;Q.push(t);}//system("pause");return 0;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.