Winter-2-STL-A Argus 解题报告及测试数据
Time Limit:2000MS Memory Limit:65536KB
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_numPeriod
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 everyPeriod 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
SampleOutput
2004 2005 2004 2004 2005
题解:这道题其实就是一个优先队列问题,用Node.now代表应出队的时间,pe代表周期,那么无非就是以下两点:
应出队时间小的先出队。应同时出队的,ID小的先出,那么重载<运算符即可。
每个节点出队之后再次应出队时间应加上周期,再次入队即可。
#include <iostream>
#include <cstdio>
#include <queue>
#include <string>
using namespace std;
struct Node{
int ID,pe,now;//pe代表周期,now代表应出队时间
}t;
bool operator < (Node t1,Node t2){
//优先队列,出队顺序,时间小的先出,时间一致,ID小的先出
return t1.now>t2.now || (t1.now==t2.now && t1.ID>t2.ID);
}
int main(){
//freopen("1.in","r",stdin);
char str[100];
int K;
priority_queue<Node>q;
while(scanf("%s",str)!=EOF && str[0]!='#'){
scanf("%d%d",&t.ID,&t.pe);
t.now = t.pe;
q.push(t);
}
scanf("%d",&K);
while(K--){
t = q.top();q.pop();
printf("%d\n",t.ID);
t.now += t.pe;//每次出队,将now+pe后入队
q.push(t);
}
}
Winter-2-STL-A Argus 解题报告及测试数据的更多相关文章
- poj 2051.Argus 解题报告
题目链接:http://poj.org/problem?id=2051 题目意思:题目有点难理解,所以结合这幅图来说吧---- 有一个叫Argus的系统,该系统支持一个 Register 命令,输入就 ...
- sgu 104 Little shop of flowers 解题报告及测试数据
104. Little shop of flowers time limit per test: 0.25 sec. memory limit per test: 4096 KB 问题: 你想要将你的 ...
- Spring-2-H Array Diversity(SPOJ AMR11H)解题报告及测试数据
Array Diversity Time Limit:404MS Memory Limit:0KB 64bit IO Format:%lld & %llu Descript ...
- Spring-2-J Goblin Wars(SPOJ AMR11J)解题报告及测试数据
Goblin Wars Time Limit:432MS Memory Limit:0KB 64bit IO Format:%lld & %llu Description Th ...
- Spring-2-B Save the Students(SPOJ AMR11B)解题报告及测试数据
Save the Students Time Limit:134MS Memory Limit:0KB 64bit IO Format:%lld & %llu Descri ...
- Spring-2-A Magic Grid(SPOJ AMR11A)解题报告及测试数据
Magic Grid Time Limit:336MS Memory Limit:0KB 64bit IO Format:%lld & %llu Description Tha ...
- Spring-1-I 233 Matrix(HDU 5015)解题报告及测试数据
233 Matrix Time Limit:5000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Descript ...
- Spring-1-H Number Sequence(HDU 5014)解题报告及测试数据
Number Sequence Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Pro ...
- Spring-1-F Dice(HDU 5012)解题报告及测试数据
Dice Time Limit:1000MS Memory Limit:65536KB Description There are 2 special dices on the table. ...
随机推荐
- superresolution_v_2.0 Application超分辨率程序文档
SUPERRESOLUTION GRAPHICAL USER INTERFACE DOCUMENTATION Contents 1.- How to use this application. 2.- ...
- Microsoft Word、Excel、PowerPoint转Pdf
Worksheet.ExportAsFixedFormat Method Mark: The ExportAsFixedFormat method is used to publish a workb ...
- 论坛模块__发帖时使用FCKeditor
论坛模块__发帖时使用FCKeditor 测试 <html> <head> <meta http-equiv="content-type" conte ...
- Spring.NET学习笔记——目录(原)
目录 前言 Spring.NET学习笔记——前言 第一阶段:控制反转与依赖注入IoC&DI Spring.NET学习笔记1——控制反转(基础篇) Level 200 Spring.NET学习笔 ...
- 递归删除资源树 Ztree
前言 最近项目里有这么一个需求:现在有一个用Ztree编写的资源树,当删除资源树的某个节点时,则将此节点下面的所有节点全部删除,这里显然就用到了递归:若此节点被删除后无其它的兄弟节点了,我们还需要将其 ...
- Android 将时间戳转为代表"距现在多久之前"的字符串
public String getStandardDate(int dateTime) { StringBuffer sb = new StringBuffer(); long t = Long.pa ...
- [算法][LeetCode]Single Number——异或运算的巧妙运用
题目要求 Given an array of integers, every element appears twice except for one. Find that single one. N ...
- 初级Java面试题 - JavaSE篇
p{font-size:18px;} li{font-size:18px;} 加入我的QQ群(701974765) 获取更多好用又好玩的软件,还有不定期发放的福利呦(- ̄▽ ̄)- Java基本数据类型 ...
- poj3585 Accumulation Degree【树形DP】【最大流】
Accumulation Degree Time Limit: 5000MS Memory Limit: 65536K Total Submissions:3151 Accepted: 783 ...
- echart使用总结
以下参数都是写在option配置对象内,没有提及的配置参数欢迎查阅读echart参考手册. 一. 修改主标题和副标题 title : { text: '未来一周气温变化',//写入主标题 subtex ...