博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 2051 Argus
阅读量:7001 次
发布时间:2019-06-27

本文共 3466 字,大约阅读时间需要 11 分钟。

题目链接:

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_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

Source

 
思路就是把此次出队列的数据的出现的时间值加上它的周期,得到下次出现的时间,然后按这个时间的数据值加入大优先队列中。
 
代码:
1 #include
2 #include
3 #include
4 #include
5 6 using namespace std; 7 8 struct node 9 {10 friend bool operator<(node n1,node n2)11 {12 if(n1.time==n2.time) return n1.ID>n2.ID; //如果时间相同则按,ID号从小到大13 return n1.time>n2.time; //优先级按秒数从小到大14 }15 int ID;16 int Period;17 int time;18 };19 20 21 int main()22 {23 char s[20];24 int ID,Period,T;25 int i;26 node temp;27 priority_queue
qn; //声明一个优先队列28 while(scanf("%s",s))29 {30 if(s[0]=='#') break;31 scanf("%d%d",&ID,&Period);32 temp.ID=ID;33 temp.Period=Period;34 temp.time=Period;35 qn.push(temp); //入队列36 }37 scanf("%d",&T);38 while(T--)39 {40 temp=qn.top(); //把队列头部的数据赋值给temp41 qn.pop(); //出队列42 temp.time+=temp.Period; //计算下次出现此ID号的秒数43 qn.push(temp); //把得到的新数据加入队列44 printf("%d\n",temp.ID);45 }46 return 0;47 }

 

转载于:https://www.cnblogs.com/gantaiyuan/p/3515133.html

你可能感兴趣的文章
Python之lxml
查看>>
取球游戏_nyoj_518(博弈-蓝桥杯原题).java
查看>>
【Servlet】Filter过滤器的编写和配置
查看>>
FZU-1925+几何
查看>>
ZStack之ZDApp_Init解析
查看>>
【FFmpeg】FFmpeg常用基本命令
查看>>
Linux 查看设置系统语言
查看>>
编译cm12.1
查看>>
Ehcache入门经典:第二篇ehcache.xml的参数
查看>>
阿里云物联网平台体验(NetGadgeteer+C#篇)
查看>>
mongdb开始标记
查看>>
啥叫多Targets, 有啥用!
查看>>
数学之路(3)-机器学习(3)-机器学习算法-SVM[7]
查看>>
linux内核源码结构
查看>>
CCM加密学习
查看>>
ZigBee profile
查看>>
127.0.0.1\SQLEXPRESS连接异常
查看>>
在linux上安装psycopg2出错--Error: pg_config executable not found.
查看>>
6款强大的 jQuery 网页布局创建及优化插件
查看>>
圆珠笔芯为什么那么细
查看>>