Argus , Beijing 2004 ,LA 3135

介绍了一种名为Argus的数据流管理系统,该系统能够实时处理连续数据流并按需返回查询结果。用户可以注册不同周期的查询,系统将按顺序返回首个K个查询结果。

题目描述

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. 

输入

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). 

输出

You should output the Q_num of the first K queries to return the results, one number per line.

样例输入

Register 2004 200Register 2005 300#5

样例输出

20042005200420042005
题目解说:

你的任务是编写一个称为Argus的系统。该系统支持一个Register命令

                     Register num period

该命令注册了一个触发器,它每Period秒钟就会产生一次编号为num的事件。你的任务是模拟出前k个事件。如果多个事件同时发生,先处理num小的时间。

【输入格式】

输入仅包含一组数据。前若干行是Register命令,以“#”结尾;最后一行是整数k。对于每条命令,1<=num,period<=3 000。k<=10 000。命令条数n不超过1 000。

【输出格式】

输出k行,即前k个事件的num。

【分析】

用优先队列来维护每个触发器的“下一个事件”,然后每次从中取出最早发生的一个事件,重复k次即可。任何时刻优先队列中都是n个元素,因此总时间复杂度为O(klogn)。

CODE:

#include <iostream>
#include <queue>
using namespace std;

//优先队列中的元素 
struct ID{
	int num, period, time;
	//重要!优先级比较函数。优先级高的先出队 
	bool operator < (const ID& x) const{ //这里的const必不可少,请读者注意 
		return time > x.time || (time == x.time && num > x.num);
	}
};

int main(){
	priority_queue<ID> p;
	char s[20];
	
	while(cin>>s && s[0] != '#'){
		ID id;
		cin>>id.num>>id.period;
		id.time = id.period;	//初始化“下一次事件的时间”为它的周期 
		p.push(id); 
	}
	
	int k;
	cin>>k;
	while(k--){
		ID id2 = p.top();	//取下一个周期 
		p.pop();
		cout<<id2.num<<endl;
		id2.time += id2.period;	//更新该触发器的“下一个事件”的时间 
		p.push(id2); 			//重新插入优先队列 
	}
	return 0;
} 



Matlab基于粒子群优化算法及鲁棒MPPT控制器提高光伏并网的效率内容概要:本文围绕Matlab在电力系统优化与控制领域的应用展开,重点介绍了基于粒子群优化算法(PSO)和鲁棒MPPT控制器提升光伏并网效率的技术方案。通过Matlab代码实现,结合智能优化算法与先进控制策略,对光伏发电系统的最大功率点跟踪进行优化,有效提高了系统在不同光照条件下的能量转换效率和并网稳定性。同时,文档还涵盖了多种电力系统应用场景,如微电网调度、储能配置、鲁棒控制等,展示了Matlab在科研复现与工程仿真中的强大能力。; 适合人群:具备一定电力系统基础知识和Matlab编程能力的高校研究生、科研人员及从事新能源系统开发的工程师;尤其适合关注光伏并网技术、智能优化算法应用与MPPT控制策略研究的专业人士。; 使用场景及目标:①利用粒子群算法优化光伏系统MPPT控制器参数,提升动态响应速度与稳态精度;②研究鲁棒控制策略在光伏并网系统中的抗干扰能力;③复现已发表的高水平论文(如EI、SCI)中的仿真案例,支撑科研项目与学术写作。; 阅读建议:建议结合文中提供的Matlab代码与Simulink模型进行实践操作,重点关注算法实现细节与系统参数设置,同时参考链接中的完整资源下载以获取更多复现实例,加深对优化算法与控制系统设计的理解。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值