Original question:
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 n um≤3000) is a query id-number, and Period (0 < period≤3000) is the interval b Etween 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 200
Register 2005 300
#
5
Sample Output
2004
2005
2004
2004
2005
English:
Give you a bunch of orders, each command is divided into register Q_num Period, indicating that every Period seconds will produce a q_num. Now let you output the number of the top K q_num. If multiple events occur at the same time, the Q_num small is processed first.
#include <bits/stdc++.h> using namespace std;
struct Reg {int q,p,mark;
Reg (int qq,int pp) {q=qq;
P=PP;
Mark=p; } BOOL operator > (const reg &R) Const {if (This->mark!=r.mark) return This->mark
>r.mark;
else return this->q>r.q;
}
};
Vector<reg> VR;
string S;
int q,p,k;
void Solve () {priority_queue<reg,vector<reg>,greater<reg>> PQ (Vr.begin (), Vr.end ());
while (k>0) {reg ans=pq.top ();
Pq.pop ();
cout<<ans.q<< "" <<ans.p<< "" <<ans.mark<<endl;
cout<<ans.q<<endl;
k--;
ANS.MARK+=ANS.P;
Pq.push (ANS);
} while (!pq.empty ()) Pq.pop ();
Vr.clear ();
} int main () {Ios::sync_with_stdio (false);
while (Cin>>s) {if (s== "#") {cin>>k;
Solve (); } ELSE {cin>>q>>p;
Reg R (q,p);
Vr.push_back (R);
}} return 0;
}
Solution: The
Training Guide is followed by the topic "A simple question," and the Asian regional tournament has such a simple subject. The
is simple, as long as these commands according to period from small to large build a heap, heap top must be the smallest period, the output and then pop up, the time just output command added a period, and then put back in the heap. Before the output of K can be.