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 解题思路:
假设绝对时间T,容易发现,对每一个query,每当T增加period时就会进行输出。我们不妨这样想,每次输出的query都是离下一次输出需要时间最少的。那么我们就可以采用优先队列存储query,记下一次输出时间为cnt,cnt越小的query优先级越高,每次取队列头元素,输出之后执行cnt+=period,再存入队列。
注意:
优先队列默认元素越大优先级越高,因此定义静态成员函数‘<’时按大于号来定义。 代码如下:
#include <iostream>
#include <time.h>
#include <queue>
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm> #define _clock (double(clock())/CLOCKS_PER_SEC) using namespace std; char buff[]; struct query{
int Q_num;
int Period;
int cnt;
query(int q=,int p=):Q_num(q),Period(p){cnt=Period;}
bool operator <(const query& a)const {
return (cnt>a.cnt)||((cnt==a.cnt)&&Q_num>a.Q_num);
}
}; priority_queue<query> u;
int q,p,k; int main(){
while(scanf("%s",buff)==&&buff[]!='#'){
scanf("%d%d",&q,&p);
u.push(query(q,p));
}
scanf("%d",&k);
while(k--){
query a=u.top();u.pop();
cout<<a.Q_num<<endl;
a.cnt+=a.Period;
u.push(a);
}
//cout<<"time : "<<_clock<<endl;
return ;
}
 

Argus--[优先队列]的更多相关文章

  1. [caffe]linux下安装caffe(无cuda)以及python接口

    昨天在mac上折腾了一天都没有安装成功,晚上在mac上装了一个ParallelDesktop虚拟机,然后装了linux,十分钟就安装好了,我也是醉了=.= 主要过程稍微记录一下: 1.安装BLAS s ...

  2. [Swift]基础

    [Swift]基础 一, 常用变量 var str = "Hello, playground" //变量 let str1="Hello xmj112288" ...

  3. [Ruby on Rails系列]4、专题:Rails应用的国际化[i18n]

    1. 什么是internationalization(i18n)? 国际化,英文简称i18n,按照维基百科的定义:国际化是指在设计软件,将软件与特定语言及地区脱钩的过程.当软件被移植到不同的语言及地区 ...

  4. [译]一个灵活的 Trello 敏捷工作流

    [译]一个灵活的 Trello 敏捷工作流 翻译自 An Agile Trello Workflow That Keeps Tasks Flexible Getting things done 可不只 ...

  5. iOS10收集IDFA,植入第三方广告[终结]--ADMob

    [PS: 前段时间,公司做ASO推广,需要在应用中收集IDFA值,跟广告平台做交互!于是有了这个需求--] 1.首先,考虑了一下情况(自己懒 -_-#),就直接在首页上写了一个Banner,循环加载广 ...

  6. Java基础 之软引用、弱引用、虚引用 ·[转载]

    Java基础 之软引用.弱引用.虚引用 ·[转载] 2011-11-24 14:43:41 Java基础 之软引用.弱引用.虚引用 浏览(509)|评论(1)   交流分类:Java|笔记分类: Ja ...

  7. CSU 1642 Problem B[难][前缀和]

    Description 已知两个正整数a和b,求在a与b之间(包含a和b)的所有整数的十进制表示中1出现的次数. Input 多组数据(不超过100000组),每组数据2个整数a,b.(1≤a,b≤1 ...

  8. [ufldl]Supervised Neural Networks

    要实现的部分为:forward prop, softmax函数的cost function,每一层的gradient,以及penalty cost和gradient. forwad prop forw ...

  9. [干货]2017已来,最全面试总结——这些Android面试题你一定需要

        地址.http://blog.csdn.net/xhmj12/article/details/54730883 相关阅读: 吊炸天!74款APP完整源码! [干货精品,值得收藏]超全的一线互联 ...

随机推荐

  1. TyvjP2018 「Nescafé26」小猫爬山

    P2018 「Nescafé26」小猫爬山 时间: 1000ms / 空间: 131072KiB / Java类名: Main 背景 Freda和rainbow饲养了N只小猫,这天,小猫们要去爬山.经 ...

  2. Elasticsearch 启动需要密码?

    vagrant@homestead:~$ systemctl disable elasticsearch.service Synchronizing state of elasticsearch.se ...

  3. day16 web前端之JavaScript

    页面布局补充 样例页面: 示例代码: <!DOCTYPE html> <html lang="en"> <head> <meta char ...

  4. Objectarx之分批存储相连实体

    void CCommonFuntion::BatchStorageEnt(AcDbObjectIdArray& inputId, std::vector<std::vector<A ...

  5. 通过反射 修改访问和修改属性的值 Day25

    package com.sxt.field; /* * 通过反射拿到属性值 * 修改public属性值 * 修改private属性值 * 缺点:可读性差:代码复杂 * 优点:灵活:可以访问修改priv ...

  6. 2019-6-23-开源项目使用-appveyor-自动构建

    title author date CreateTime categories 开源项目使用 appveyor 自动构建 lindexi 2019-06-23 11:47:40 +0800 2019- ...

  7. HZOJ 太阳神

    所以我刚学反演还没学反演就要做这么一道神仙题…… 首先大于n不好求,补集转化. $ans=n*n-\sum \limits _{i=1}^{n} \sum \limits _{j=1}^{n} \le ...

  8. HDU 5584 LCM Walk【搜索】

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5584 题意: 分析: 这题比赛的时候卡了很久,一直在用数论的方法解决. 其实从终点往前推就可以发现, ...

  9. Java“封装”的例子

    /*功能:Java"封装"的典型例子*/ public class Demo3_5{    public static void main(String args[]){      ...

  10. 删除username的索引

    -- 删除index_name 索引 drop index index_name on user; show index from user \G; -- 创建新索引列组成,index_pinyin为 ...