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


相关推荐

  • python数据库操作之sqlalchemy逆向工程

    python数据库操作之sqlalchemy逆向工程依赖安装pipinstallsqlacodegen数据库配置config.pyimportosHOST=’localhost’PORT=3306USERNAME=’root’PASSWORD=’root’DB=’demo’DB_URI=f’mysql+pymysql://{USERNAME}:{PASSWORD}@{HOST}:{PORT}/{DB}’#自动生成modelsos.system(f’sqlacodegen{DB_URI}

  • 利用CSkin组件设计漂亮的WinForm登录界面「建议收藏」

    利用CSkin组件设计漂亮的WinForm登录界面「建议收藏」众所周知,WinForm具有快速开发的优点,但是美观方面一直被人诟病,一般美化都是采用第三方的组件来满足美化效果,这里我也利用Cskin组件来设计一个具有一定美感的登录界面,CSkin下载CSkin的使用你可以自行查看下载后的文档或者另行百度,这里就不介绍了,关于CSkin的美化登录界面简单介绍,主要是利用背景图片结合CSkin界面和控件的效果来实现的,如果你中别人的登录界面,你也可以截取别人的登录界面,然后用自己的控件覆盖人家的登录输入位置,覆盖别人的logo或者系统名称等,这也是一种技巧。

  • 免费的集群软件_服务器集群软件

    免费的集群软件_服务器集群软件概述 IBM高可用性集群软件(HighAvailabilityClusterMultiprocessing(HACMPTM))支持广泛的配置,为集群管理员提供了非常高的灵活性。这种灵活性带来了多种的选择:有许多可行的集群配置可以通过一般的审核以及上线运行,但是却没有优化以提供应有的可用性。本文讨论了集群设计人员可以做出的选择,从可选方案中提出建议,以帮助最高的可用性级别。 

    2022年10月15日
  • 全局低级键盘钩子[通俗易懂]

    全局低级键盘钩子[通俗易懂]/*========================================================================文件:kbevent.h说明:全局消息钩子时间:2005-03-20编写:oshj||oshj@21cn.c

  • activity中onResume方法详解[通俗易懂]

    activity中onResume方法详解[通俗易懂]onResume比如做一个音乐播放程序,在播放过程中,突然有电话打进来了,这时系统自动调出电话,而你的音乐播放程序置于后台,触发了onPause方法。当你电话结束后,关闭电话,又自动回到音乐播放程序,此时,触发onResume方法,这时,如果你之前在onPause的时候记录了播放点,就可以在onResume方法里来继续播放。onResume方法是Activity第一次创建时重新加载实例时调用…

  • jmeter如何确保输入的参数为唯一字段

    jmeter如何确保输入的参数为唯一字段

发表回复

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

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