博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UVALive3135 UVA1203 POJ2051 ZOJ2212 Argus【优先队列】
阅读量:6235 次
发布时间:2019-06-22

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

Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 11450   Accepted: 5545

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

 >> 

问题链接

问题简述每个用户注册一个ID号,并且有一个间隔时间。对于每个用户,每隔一个间隔时间打印一次。注册的用户到“#”为止。之后给出k,是需要打印的用户ID数量。

问题分析用优先队列来解决是最合适的。

程序说明:(略)

题记:(略)

参考链接:(略)

AC的C++语言程序如下:

/* UVALive3135 UVA1203 POJ2051 ZOJ2212 Argus */#include 
#include
using namespace std;struct _node { int num, period, cnt; bool operator <(_node a)const { if(cnt != a.cnt) return cnt > a.cnt; else return num > a.num; }};int main(){ priority_queue<_node> q; _node t; string s; int k; while(cin >> s) { if(s == "#") break; else { cin >> t.num >> t.period; t.cnt = t.period; q.push(t); } } cin >> k; while(k--) { t = q.top(); q.pop(); cout << t.num << endl; t.cnt += t.period; q.push(t); } return 0;}

转载于:https://www.cnblogs.com/tigerisland/p/7563574.html

你可能感兴趣的文章
使用正则表达式,取得点击次数,函数抽离
查看>>
TensorFlow学习---入门(一)-----MNIST机器学习
查看>>
[LeetCode] Reverse Words in a String II
查看>>
[LeetCode] Find Peak Element
查看>>
appium ios环境搭建——iOS开发环境搭建
查看>>
20155222卢梓杰 课堂测试ch06补做
查看>>
20155222卢梓杰 实验五 MSF基础应用
查看>>
android分析之Thread类
查看>>
【总结整理】WebGIS基础
查看>>
linux(一)export的生命周期
查看>>
[转载].NET开发常用的10条实用代码
查看>>
用邻接表实现DFS和BFS
查看>>
PHP实现自己活了多少岁
查看>>
安装 Ruby, Rails 运行环境 常见的错误
查看>>
eclipse 自动提示不出来
查看>>
Java 开发 2.0: 现实世界中的 Redis
查看>>
并查集——新手学习记录
查看>>
杭电Acm-1010,1016,1240解题心得
查看>>
Git命令使用小结
查看>>
1025. 水枪灭火——java
查看>>