poj2051 Argus
Description
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 second part is your task. This part contains only one line, which is one positive integer K (<= 10000).
Output
Sample Input
Register 2004 200
Register 2005 300
#
5
Sample Output
2004
2005
2004
2004
2005 思路:裸的优先队列题,存起来当模板
/*
* Author: Joshua
* Created Time: 2014年07月10日 星期四 16时10分11秒
* File Name: poj2501.cpp
*/
#include<cstdio>
#include<queue> using namespace std; typedef long long LL; struct item
{
int Qnum,period,time;
bool operator < (const item &a) const
{
return time > a.time || (time == a.time && Qnum >a.Qnum);
}
}; void solve()
{
priority_queue<item> pq;
char s[]; while (scanf("%s", s ) && s[]!='#')
{
item item;
scanf("%d%d",&item.Qnum,&item.period);
item.time=item.period;
pq.push(item);
} int t;
scanf("%d",&t);
while (t--)
{
item r = pq.top();
pq.pop();
printf("%d\n",r.Qnum);
r.time +=r.period;
pq.push(r);
}
} int main()
{
solve();
return ;
}
poj2051 Argus的更多相关文章
- 二叉堆(binary heap)
堆(heap) 亦被称为:优先队列(priority queue),是计算机科学中一类特殊的数据结构的统称.堆通常是一个可以被看做一棵树的数组对象.在队列中,调度程序反复提取队列中第一个作业并运行,因 ...
- poj 2051.Argus 解题报告
题目链接:http://poj.org/problem?id=2051 题目意思:题目有点难理解,所以结合这幅图来说吧---- 有一个叫Argus的系统,该系统支持一个 Register 命令,输入就 ...
- Argus
Argus Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 10186 Accepted: 4801 Description A ...
- 【暑假】[实用数据结构]UVAlive 3135 Argus
UVAlive 3135 Argus Argus Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %l ...
- LA-3135 - Argus(优先队列)
3135 - Argus A data stream is a real-time, continuous, ordered sequence of items. Some examples incl ...
- UVA 1203 - Argus(优先队列)
UVA 1203 - Argus 题目链接 题意:给定一些注冊命令.表示每隔时间t,运行一次编号num的指令.注冊命令结束后.给定k.输出前k个运行顺序 思路:用优先队列去搞,任务时间作为优先级.每次 ...
- uva 1203 - Argus(优先队列)
option=com_onlinejudge&Itemid=8&page=show_problem&problem=3644" target="_blank ...
- Winter-2-STL-A Argus 解题报告及测试数据
Time Limit:2000MS Memory Limit:65536KB Description A data stream is a real-time, continuous, ord ...
- ACM解题之(ZOJ 2212) Argus
题目来源: 点击打开题目 题目翻译: 数据流是实时的,连续的,有序的项目序列.一些例子包括传感器数据,互联网流量,金融代码,在线拍卖以及诸如网络使用日志和电话记录之类的交易日志.同样,对流进行的查询在 ...
随机推荐
- 游戏里的动态阴影-ShadowMap实现原理
ShadowMap是比较流行的实时阴影实现方案,原理比较简单,但真正实现起来还是会遇到很多问题的,我这里主要记录下实现方式 先看效果 凹凸地形上也有阴影 实现原理 ShadowMap技术是从灯光空间用 ...
- tensorflow softsign函数应用
1.softsign函数 图像 2.tensorflow softsign应用 import tensorflow as tf input=tf.constant([0,-1,2,-30,30],dt ...
- (转)java并发之Executor
场景: 线程池在面试时候经常会碰到,在工作中用的场景更多,所以很有必要弄清楚. 1 简介 Java自1.5以来加入了处理一批线程的方法,也就是java并发包里的Executor.本文主要介绍Execu ...
- [BZOJ 4325][NOIP 2015] 斗地主
一道防AK好题 4325: NOIP2015 斗地主 Time Limit: 30 Sec Memory Limit: 1024 MBSubmit: 820 Solved: 560[Submit] ...
- 关于vue组件的一个小结
用vue进行开发到目前为止也有将近一年的时间了,在项目技术选型的时候隔壁组选 react的时候我们坚持使用vue作为前端的开发框架.虽然两者思想上的差异不大,但是vue的语法在代码的可读性以及后期的维 ...
- Android学习笔记-绘制圆形ImageView实例
现在很多的APP都很喜欢圆形的头像,这里就简单的写个圆形的ImageView~ 第三方圆形ImageView控件: RoundedImageView CircleImageView 实现代码: 自定义 ...
- Linux修改网卡名称、主机名
Linux修改网卡名称.主机名 环境:VirtualBox 5.0.14 + RHEL 6.5 需求:个人实验搭建一套Standby RAC时,为了节约时间,直接复制之前安装RAC的主机模板. 但复制 ...
- matlab怎么查看已安装哪些工具箱和…
问题描述:matlab怎么查看已安装哪些工具箱和它们相应的版本 解决方法:在命令行里敲击der,回车 效果:
- 52. leetcode 96. Unique Binary Search Trees
96. Unique Binary Search Trees Given n, how many structurally unique BST's (binary search trees) tha ...
- 《开发技巧》WEB APP开发调试技巧
前言 随着html5和nodejs的兴起.web APP越来越火,一套代码可以多平台使用.减少了很大的开发成本.很多APP中也集成了很多的html5页面,增强很高的应用体验.所以移动端页面也事关重要! ...