"Summer Vacation" [Practical data structure]uvalive 3135 Argus

Source: Internet
Author: User

Uvalive 3135 Argus

Argus
Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld &%llu

Submit Status

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 arr Ives. For example, a temperature detection system of a factory warehouse if 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 all floor over the past minutes.?

We have developed a data Stream Management System called Argus and which processes the queries over the data streams. Users can register queries to the Argus. Argus would keep the queries running over the changing data and return the results-the corresponding user with the Desir Ed frequency.

For the Argus, we use the following instruction to register a query:

Register q_num Period

Q_num (0 < q_num≤3000) is a query id-number, and Period (0 < period≤3000) is the interval between the consecutive Returns of the result. After Period seconds of register, the result would be returned for the first time, and after, the result would be retur Ned every Period seconds.

Here we have the several different queries registered in Argus at once. It is confirmed and all the queries has different q_num. Your task is to tell the first K queries to return the results. If or more queries is to return the results at the same time, they'll return the results one by one in the Ascendin G Order of Q_num.

Input

The first part of the input is the register instructions to Argus, one instruction per line. You can assume the number of the instructions would not be exceed, and all these instructions is executed at the same ti Me. This was 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

--------------------------------------------------------------------------------------------------------------- -----------------------------------------

Ideas :
Priority queue emulation. The time is small, the priority is high, each time the smallest out of the queue record qnum after the change to re-queue (meaning that the task goes to the next round)
Note: Overloaded operators in the priority queue are special, I understand that: the default priority_queue in STL is a large heap, and we need small Gan, so the < overload is the opposite sign.

Code:

1 //Processor Emulation2#include <cstdio>3#include <queue>4 #definefor (A,B,C) for (int a= (b);a< (c); a++)5 using namespacestd;6 7 structnode{8     intQnum,period,time;9     BOOL operator< (Constnode& RHS)Const{  Ten      returnTime>rhs.time | | (Time==rhs.time && qnum>rhs.qnum); One     } A }; - //The priority queue defaults to the large heap, and the need for "small Gan" is therefore defined in the opposite way < -  the intMain () { -Priority_queue<node>Q; - Chars[ -]; - Node x; +  -    while(SCANF ("%s", s) && s[0] !='#'){ +scanf"%d%d",&x.qnum,&x.period); AX.time=x.period;//Time_init at Q.push (x); -   } -   intK scanf"%d",&k); -    while(k--){ -x=Q.top (); Q.pop (); -printf"%d\n", x.qnum); inX.time + = X.period;//change the time for the next round back to the priority queue - Q.push (x); to   } +   return 0; -}


"Summer Vacation" [Practical data structure]uvalive 3135 Argus

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.