(算法入门经典大赛 优先级队列)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;}

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

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

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

  • java在线播放_Java实现视频在线播放flv视频

    java在线播放_Java实现视频在线播放flv视频1、首先使用Idea创建一个SpringBoot项目。2、在application.properties文件下加入以下代码,进行DEBUG日志输出,配置pom.xml文件:#logging日志配置logging.level.root=WARNlogging.level.org.springframework.web=DEBUG4.0.0com.exampledemo0.0.1-SNAPSHOTj…

  • 服务器cpu型号后面的字母,Intel 至强 E3服务器CPU后缀解读[通俗易懂]

    服务器cpu型号后面的字母,Intel 至强 E3服务器CPU后缀解读[通俗易懂]三、Intel至强E3服务器CPU后缀解读DIY玩家认识服务器CPU最多的无疑是E3神教,今天我们就总结下XeonE3神教的CPU后缀有什么特色。●V1-V5E3神教!从SNB开始,Intel就推出了E3系列至强CPU。由于阵脚一样,只需升级BIOS就能享用信仰级至强CPU,让2011年开始E3神教开始壮大。Intel也推出了E3的后续型号,与历代酷睿对应,从IvyBridge的V2到Sk…

  • HTML的表单元�

    HTML的表单元�

  • UE4 显示帧率的几种姿势「建议收藏」

    在使用UE4Editor或者UE4Game时,有时候需要查看帧率,以及每帧耗时情况。在Editor中显示:键盘上按下~可以看到有个输入框出现:在输入框输入statfps或者statunit,出现帧率或者耗时:在Game中显示(1):启动Game.exe后,键盘按下~出现输入框,输入框中输入statfps或者statunit,回车:在

  • Linux文件—文件锁

    Linux文件—文件锁通过之前的open()/close()/read()/write()/lseek()函数已经可以实现文件的打开、关闭、读写等基本操作,但是这些基本操作是不够的。对于文件的操作而言,“锁定”操作是对文件(尤其是对共享文件)的一种高级的文件操作。当某进程在更新文件内数据时,期望某种机制能防止多个进程同时更新文件从而导致数据丢失,或者防止文件内容在未更新完毕时被读取并引发后续问题,这种机制就是“文件锁”。

  • java版我的世界下载_我的世界java版

    java版我的世界下载_我的世界java版我的世界java版这个所谓的java版可能大家不是很熟悉,java版就是《我的世界》是整个游戏的初始版本,目前Java版本是全平台游戏版本中内容最多,更新速度最快的版本。此外,Java版本拥有大规模的全球玩家社区,得益于它可拓展的特性,拥有百万件玩家创意作品,这些都使得Java版本是核心玩家最喜爱的版本之一。我的世界java版手机版种子:出生点前有丛林神庙的地图种子在这个种子地图上,你会出生在一座…

发表回复

您的电子邮箱地址不会被公开。

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