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[]; while (scanf("%s", s ) && s[]!='#')
{
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 ;
}

poj2051 Argus的更多相关文章

  1. 二叉堆(binary heap)

    堆(heap) 亦被称为:优先队列(priority queue),是计算机科学中一类特殊的数据结构的统称.堆通常是一个可以被看做一棵树的数组对象.在队列中,调度程序反复提取队列中第一个作业并运行,因 ...

  2. poj 2051.Argus 解题报告

    题目链接:http://poj.org/problem?id=2051 题目意思:题目有点难理解,所以结合这幅图来说吧---- 有一个叫Argus的系统,该系统支持一个 Register 命令,输入就 ...

  3. Argus

    Argus Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 10186 Accepted: 4801 Description A ...

  4. 【暑假】[实用数据结构]UVAlive 3135 Argus

    UVAlive 3135 Argus Argus Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %l ...

  5. LA-3135 - Argus(优先队列)

    3135 - Argus A data stream is a real-time, continuous, ordered sequence of items. Some examples incl ...

  6. UVA 1203 - Argus(优先队列)

    UVA 1203 - Argus 题目链接 题意:给定一些注冊命令.表示每隔时间t,运行一次编号num的指令.注冊命令结束后.给定k.输出前k个运行顺序 思路:用优先队列去搞,任务时间作为优先级.每次 ...

  7. uva 1203 - Argus(优先队列)

    option=com_onlinejudge&Itemid=8&page=show_problem&problem=3644" target="_blank ...

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

    Time Limit:2000MS     Memory Limit:65536KB Description A data stream is a real-time, continuous, ord ...

  9. ACM解题之(ZOJ 2212) Argus

    题目来源: 点击打开题目 题目翻译: 数据流是实时的,连续的,有序的项目序列.一些例子包括传感器数据,互联网流量,金融代码,在线拍卖以及诸如网络使用日志和电话记录之类的交易日志.同样,对流进行的查询在 ...

随机推荐

  1. 小型 Web 页项目打包优化方案

    背景   目前团队中新的 Web 项目基本都采用了 Vue 或 React ,加上 RN,这些都属于比较重量级的框架,然而对于小型 Web 页面,又显得过大.早期的一些项目则使用了较原始的 HTML ...

  2. Maven安装及使用-超级图文初级篇-

    针对新手刚接触maven,并且不知道如何去搭建和使用maven,那么我来写一篇浅显易懂的初级篇教程吧. 不同的是,别人会先将概念再安装,我来帮大家先搭建好以后再去看概念,不然概念会变的很模糊. 安装: ...

  3. Python简易爬虫爬取百度贴吧图片

    通过python 来实现这样一个简单的爬虫功能,把我们想要的图片爬取到本地.(Python版本为3.6.0) 一.获取整个页面数据 def getHtml(url): page=urllib.requ ...

  4. Hive笔记——技术点汇总

    目录 · 概况 · 手工安装 · 引言 · 创建HDFS目录 · 创建元数据库 · 配置文件 · 测试 · 原理 · 架构 · 与关系型数据库对比 · API · WordCount · 命令 · 数 ...

  5. 【Lab】Python改bat文件

    [Lab]Python改bat文件 给出一个特定的树形结构,每一层的数字依次递增后,按照从上到下,同时从左到右这样的顺序生成.这么说还是不太明白,比如下面这个简单的树形结构. 按照顺序应该写成这样[3 ...

  6. unable to create …

    问题描述: 在新建Android Application时会出现unable to create the selected property page 解决方法: 将用户PATH路径中的jdk路径放到 ...

  7. Struts2漏洞解决

    如果你也正在使用Struts2作为web层框架做开发或者做公司的送检产品,然后被告知有各种各样的Struts2漏洞,那本篇博客值得你花时间来喽上一两眼. 前端时间抽空为公司做了新一代的送检产品,为了方 ...

  8. There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).

    解题思路:合并两个数组,创建一个 Map对象,用以存放排好顺序的键值对,键为序号,值为数组值,中位数的结果分两种情况讨论: 1.m+n为奇数:(m+n)/2为中位数 2.m+n为偶数:(((m+n)/ ...

  9. NYOJ--139--我排第几个(康托展开)

    我排第几个 时间限制:1000 ms  |  内存限制:65535 KB 难度:3   描述 现在有"abcdefghijkl"12个字符,将其所有的排列中按字典序排列,给出任意一 ...

  10. 1.配置vsftp服务器

    1.安装 vsftp yum -y install ftp vsftpd 2.查看配置文件所在路径 rpm -qc vsftpd 3.备份vsftpd文件 cp vsftpd.conf vsftpd. ...