(算法入门经典大赛 优先级队列)LA 3135(之前K说明)[通俗易懂]

(算法入门经典大赛 优先级队列)LA 3135(之前K说明)

大家好,又见面了,我是全栈君,今天给大家准备了Idea注册码。

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 200Register 2005 300#5

Sample output
20042005200420042005

代码例如以下:

/* * 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;}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/116749.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Java基础篇:static关键字

    Java基础篇:static关键字

    2021年10月4日
    36
  • pytest的使用_新代子程序重复调用

    pytest的使用_新代子程序重复调用Pytest执行用例规则Pytest在命令行中支持多种方式来运行和选择测试用例1.对某个目录下所有的用例pytest2.对模块中进行测试pytesttest_mod.py3.对文件夹进行

    2022年7月29日
    3
  • ssis 数据转换_SSIS数据类型:高级编辑器的更改与数据转换的转换

    ssis 数据转换_SSIS数据类型:高级编辑器的更改与数据转换的转换ssis数据转换Inthisarticle,IwillfirstgiveanoverviewofSSISdatatypesanddatatypesconversionmethodsandthenIwillillustratethedifferencebetweenchangingthecolumnsdatatypesfrom…

    2022年7月20日
    16
  • 一文搞懂MySQL索引(清晰明了)[通俗易懂]

    一文搞懂MySQL索引(清晰明了)[通俗易懂]索引是对数据库表中一列或多列的值进行排序的一种结构。MySQL索引的建立对于MySQL的高效运行是很重要的,索引可以大大提高MySQL的检索速度。MySQL中常用的索引结构(索引底层的数据结构)有:B-TREE,B+TREE,HASH等。MySQL的索引有两种分类方式:逻辑分类和物理分类。对于InnoDB和MyISAM而言,主键索引是根据主关键字来构建的B+树存储结构,辅助索引则是根据辅助键来构造的B+树存储结构,彼此的索引树都是相互独立的。

    2022年6月24日
    27
  • C++学习之路—— STL标准模板库概述

    C++学习之路—— STL标准模板库概述例题1:将课程中讲过的vector容器和list容器的操作都使用一遍。代码如下:template <typename T> void VectorShow(vector<T> v){ cout << “使用模板函数打印容器所有元素!” << endl; for (int i = 0; i < v.size(); i++) { …

    2022年8月18日
    5
  • 计算机网络网络适配器的作用是什么原因,网络适配器是什么东西?网络适配器主要功能…

    计算机网络网络适配器的作用是什么原因,网络适配器是什么东西?网络适配器主要功能…网络适配器就是俗称的网卡,网卡是工作在链路层的网络组件,是局域网中连接计算机和传输介质的接口,简单来说就是,网卡有问题网络就有问题。网卡是工作在链路层的网络组件,是连接计算机和传输介质的接口。但是很多朋友还是不知道网络适配器是什么。下面window小编就来具体说说网络适配器是什么适配器是一个接口转换器,适配器可以是一个独立的硬件接口设备也可以是信息接口。网络适配器就是一种信息接口,用来接受或发送网…

    2022年5月23日
    65

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号