24h購物| | PChome| 登入
2012-04-24 16:16:44| 人氣1,222| 回應0 | 上一篇 | 下一篇

[UVA][priority_queue] 1203 - Argus

推薦 0 收藏 0 轉貼0 訂閱站台

A data stream is a real-time, continuous, ordered sequence of items. Some examples includesensor data, Internet traffic, financial tickers, on-line auctions, and transaction logs such as Webusage logs and telephone call records. Likewise, queries over streams run continuously over aperiod of time and incrementally return new results as new data arrives. For example, atemperature 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 queriesover the data streams. Users can register queries to the Argus. Argus will keep the queries runningover 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 intervalbetween two consecutive returns of the result. After Period seconds of register, the result will bereturned 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 thequeries have different Q_num. Your task is to tell the first K queries to return the results. If two ormore queries are to return the results at the same time, they will return the results one by one inthe ascending order of Q_num.

Input 

The first part of the input are the register instructions to Argus, one instruction per line. You canassume the number of the instructions will not exceed 1000, and all these instructions are executedat 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

 

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <queue>
using namespace std;

struct Argus {
    int ID, p, v;
};
struct cmp {
    bool operator() (Argus a, Argus b) {
        if(a.v != b.v)
            return a.v > b.v;
        return a.ID > b.ID;
    }
};

int main() {
    priority_queue<Argus, vector<Argus>, cmp> Q;
    char str[50];
    int ID, p, k;
    Argus tmp;
    while(scanf("%s", str) == 1) {
        if(str[0] == '#')
            break;
        scanf("%d %d", &ID, &p);
        tmp.ID = ID, tmp.p = tmp.v = p;
        Q.push(tmp);
    }
    scanf("%d", &k);
    while(k--) {
        printf("%d\n", Q.top().ID);
        tmp = Q.top();
        Q.pop();
        tmp.v += tmp.p;
        Q.push(tmp);
    }
    return 0;
}

台長: Morris
人氣(1,222) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA][組合] 124 - Following Orders
此分類上一篇:[UVA][ConvexHull] 1206 - Boundary Points

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文