poj2051 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

思路:裸的优先队列题,存起来当模板
/*
 * Author:  Joshua
 * Created Time:  2014年07月10日 星期四 16时10分11秒
 * File Name: poj2501.cpp
 */
#include<cstdio>
#include<queue>

using namespace std;

typedef long long LL;

struct item
{
    int Qnum,period,time;
    bool operator < (const item &a) const
    {
        return time > a.time || (time == a.time && Qnum >a.Qnum);
    }
};

void solve()
{
    priority_queue<item> pq;
    char s[20];

    while (scanf("%s", s ) && s[0]!=‘#‘)
    {
        item item;
        scanf("%d%d",&item.Qnum,&item.period);
        item.time=item.period;
        pq.push(item);
    }

    int t;
    scanf("%d",&t);
    while (t--)
    {
        item r = pq.top();
        pq.pop();
        printf("%d\n",r.Qnum);
        r.time +=r.period;
        pq.push(r);
    }
}

int main()
{
    solve();
    return 0;
}

poj2051 Argus

时间: 2024-09-23 15:37:54

poj2051 Argus的相关文章

二叉堆(binary heap)

堆(heap) 亦被称为:优先队列(priority queue),是计算机科学中一类特殊的数据结构的统称.堆通常是一个可以被看做一棵树的数组对象.在队列中,调度程序反复提取队列中第一个作业并运行,因而实际情况中某些时间较短的任务将等待很长时间才能结束,或者某些不短小,但具有重要性的作业,同样应当具有优先权.堆即为解决此类问题设计的一种数据结构. 本文地址:http://www.cnblogs.com/archimedes/p/binary-heap.html,转载请注明源地址. 逻辑定义 n个

LA-3135 - Argus(优先队列)

3135 - Argus A data stream is a real-time, continuous, ordered sequence of items. Some examples include sensordata, Internet traffic, financial tickers, on-line auctions, and transaction logs such as Web usage logsand telephone call records. Likewise

Winter-2-STL-A Argus 解题报告及测试数据

Time Limit:2000MS     Memory Limit:65536KB 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 usa

poj2051&amp;&amp;UVALive 3135 水题

http://poj.org/problem?id=2051 Argus Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 9716   Accepted: 4543 Description A data stream is a real-time, continuous, ordered sequence of items. Some examples include sensor data, Internet traff

poj 2051.Argus 解题报告

题目链接:http://poj.org/problem?id=2051 题目意思:题目有点难理解,所以结合这幅图来说吧---- 有一个叫Argus的系统,该系统支持一个 Register 命令,输入就是类似样例中的: Register 2004 200 代表编号为 2004 的 Register,每隔 200 个时间单位就会产生一次.2005 同理.然后需要输出前 k 个事件.如果多个事件同时发生,就先输出编号较少的.所以在 600 这个时间上,2004 要比 2005 先输出. 第一次学 rj

UVALive - 3135 - Argus (优先队列!!)

UVALive - 3135 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, financi

uva 1203 - Argus(优先队列)

题目链接:uva 1203 - Argus 题目大意:一个成为Argus的系统,支持一个Register命令 Register Q_num Period 该命令为一个祖册出发器,每Period产生一次Q_num的时间.要求模拟k个事件,如果多个事件同时发生,现处理Q_num小的. 解题思路:用优先队列维护即可,队列中按照时间小的优先,时间相同的比较Q_num,每次处理完一个时间,对应的将时间的时间加上period后放回队列中,表示下一次出发器生成的时间. #include <cstdio> #

la 3135 Argus Data Structure

// la 3135 Argus // 学习一下优先队列的使用吧,题目还是比较简单的 // 刘老师的训练指南p188. // 继续练吧.... #include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cfloat> #include <climits> #include <cmath> #include &l

UVA 1203 - Argus(优先队列)

UVA 1203 - Argus 题目链接 题意:给定一些注冊命令.表示每隔时间t,运行一次编号num的指令.注冊命令结束后.给定k.输出前k个运行顺序 思路:用优先队列去搞,任务时间作为优先级.每次一个任务出队后,在把它下次运行作为一个新任务入队就可以 代码: #include <cstdio> #include <cstring> #include <queue> using namespace std; char str[10]; struct Task { in