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

代码例如以下:

/*
* LA_3135.cpp
*
* Created on: 2014年8月1日
* Author: pc
*/ #include <iostream>
#include <cstdio>
#include <queue> using namespace std; struct Item{
int num;//指令的序号
int period;//指令的运行周期
int time;//指令的下一次运行时间 bool operator<(const Item& b)const{
if(time != b.time){
return time > b.time;
} return num > b.num;
}
}; int main(){
char s[20]; priority_queue<Item> pq;
while(scanf("%s",&s),s[0] != '#'){
Item item;
scanf("%d%d",&item.num,&item.period);
item.time = item.period;
pq.push(item);
} int k;
scanf("%d",&k);
while(k--){//核心逻辑
Item r = pq.top();//不断的取出来然后不断的插走
pq.pop(); printf("%d\n",r.num);
r.time += r.period; pq.push(r);
} return 0;
}

(算法入门经典大赛 优先级队列)LA 3135(之前K说明)的更多相关文章

  1. 算法入门经典大赛 Dynamic Programming

    111 - History Grading LCS 103 - Stacking Boxes 最多能叠多少个box DAG最长路 10405 - Longest Common Subsequence ...

  2. 【python cookbook】【数据结构与算法】5.实现优先级队列

    问题:要实现一个队列,它能够以给定的优先级对元素排序,且每次pop操作时都会返回优先级最高的那个元素: 解决方案:采用heapq模块实现一个简单的优先级队列 # example.py # # Exam ...

  3. 《Java数据结构与算法》笔记-CH4-6优先级队列

    /** * 优先级队列 * 效率:插入O(n),删除O(1).第12章介绍如何通过堆来改进insert时间 */ class PriorityQueue { private int maxSize; ...

  4. 算法入门经典-第七章 例题7-4-1 拓展 n皇后问题 回溯法

    实际上回溯法有暴力破解的意思在里面,解决一个问题,一路走到底,路无法通,返回寻找另   一条路. 回溯法可以解决很多的问题,如:N皇后问题和迷宫问题. 一.概念 回溯算法实际类似枚举的搜索尝试过程,主 ...

  5. 算法入门经典第七章 例题7-2-1 生成1-n的排列

    输入正数n,按字典序从小到大的顺序输出n个数的所有排列.两个序列的字典序大小关系等价于从头开始第一个不相同位置处的大小关系. 递归的边界应该很好理解吧,当集合s[]中没有一个元素的时候,按照上面的伪码 ...

  6. 算法入门经典-第六章 例题6-21 SystemDependencies

    题意:软件组件之间会有依赖关系,比如你下一个Codeblocks你也得顺带着把编译器给下上.你的任务是模拟安装和卸载软件组件的过程.有以下五种指令,如果指令为“END”则退出程序:若为以下四种指令,则 ...

  7. 算法入门经典第六章 例题6-14 Abbott的复仇(Abbott&#39;s Revenge)BFS算法实现

    Sample Input 3 1 N 3 3 1 1 WL NR * 1 2 WLF NR ER * 1 3 NL ER * 2 1 SL WR NF * 2 2 SL WF ELF * 2 3 SF ...

  8. [PY3]——实现一个优先级队列

    import heapq class PriorityQueue: def __init__(self): self._queue=[] self._index=0 def push(self,ite ...

  9. 算法竞赛入门经典 LA 4329(树状数组)

    题意: 一排有着不同能力值的人比赛,规定裁判的序号只能在两人之间,而且技能值也只能在两人之间 问题: <算法竞赛入门经典-训练指南>的分析: 上代码: #include<iostre ...

随机推荐

  1. 将centos7打造成桌面系统

    前言以下所有操作默认在root权限下执行,桌面环境是kde,使用gnome的也可以参考一下.我收集的以下要用到的一些安装包,360网盘http://yunpan.cn/csMhBAp92vTgN 提取 ...

  2. linux C 9*9

    #include<stdio.h> #include<conio.h> #include <windows.h> void Gotoxy(int x, int y) ...

  3. Android组件系列----BroadcastReceiver广播接收器

    [声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/3 ...

  4. C#冒泡排序--详解

    思路:以数组int[]a={55,42,15,3,66,52};为例. 每一轮排序都把最大的数放在最后 所以, 对应循环语句思路 这样就很清晰了. 代码如下: , , , , , , , }; ; i ...

  5. 禁止apache显示目录索引

    1)修改目录配置: 复制代码 代码如下: <Directory "D:/Apache/blog.phpha.com">Options Indexes FollowSym ...

  6. [置顶] c#验证码识别、图片二值化、分割、分类、识别

    c# 验证码的识别主要分为预处理.分割.识别三个步骤 首先我从网站上下载验证码 处理结果如下: 1.图片预处理,即二值化图片 *就是将图像上的像素点的灰度值设置为0或255. 原理如下: 代码如下: ...

  7. docker打包centos增加中文支持

    docker打包centos增加中文支持 前言 使用的某个包的返回值,在本机测试时返回结果是中文,结果打包到docker后返回结果变英文了:猜测是系统语言的问题,进入docker测试了一下,发现果然是 ...

  8. iOS开源项目周报0413

    由OpenDigg 出品的iOS开源项目周报第十六期来啦.我们的iOS开源周报集合了OpenDigg一周来新收录的优质的iOS开源项目,方便iOS开发人员便捷的找到自己需要的项目工具等. glidin ...

  9. vs2013 查找进行的过程中被停止

    VS"Find in Files"失效的解决方法一:让VS窗口获得焦点,依次按以下快捷键Ctrl+BreakCtrl+Scroll LockAlt+Break VS"Fi ...

  10. tf.segment_sum和tf.unsorted_segment_sum理解实例

    本文来自 guotong1988 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/guotong1988/article/details/77622790 import ...