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
题目来源: 点击打开题目 题目翻译: 数据流是实时的,连续的,有序的项目序列.一些例子包括传感器数据,互联网流量,金融代码,在线拍卖以及诸如网络使用日志和电话记录之类的交易日志.同样,对流进行的查询在 ...
随机推荐
- [bzoj 2243]: [SDOI2011]染色 [树链剖分][线段树]
Description 给定一棵有n个节点的无根树和m个操作,操作有2类: 1.将节点a到节点b路径上所有点都染成颜色c: 2.询问节点a到节点b路径上的颜色段数量(连续相同颜色被认为是同一段),如“ ...
- maven - 引用本地jar,进行jar包移动
背景: 项目为maven工程,部分jar需要需用项目单独修改的本地jar包. 配置好scope后发现构建后引用的jar没有移动到对应的目录,百度后发现需要配置以下依赖 <plugin> & ...
- LeetCode-Palindrome Partitioning II[dp]
Palindrome Partitioning II Given a string s, partition s such that every substring of the partition ...
- 自动生成proto Js语句
在与后端的WebSocket通信时,前端要带一个proto文件是一个累赘的事情.首先是明显的曝光了协议实体对象,再一个浏览器客户端很容易会缓存该文件,新的协议更新可能导致客户端不能使用,另外在cdn服 ...
- iOS源码博文集锦3
iOS精选源码 高仿淘宝首页 登录动画 iOS高德二次封装,有定位,轨迹,语音实时导航,GPS纠偏..... 逗视iOS客户端MGDS_Swift 两句代码搞定转场动画 自定义刷新控件 已封装支持自定 ...
- .net Ajax使用
function CheckUsername() { var strName = $("#txtUserName").val(); $.ajax({ type: "GET ...
- HtmlCleaner CleanerProperties 参数配置(转自macken博客,链接:http://macken.iteye.com/blog/1579809)
HtmlCleaner CleanerProperties 参数配置 Parameter Default Explanation advancedXmlEscape true If this para ...
- 应届毕业生如何通过学习Linux系统选择一份高薪职业
2017年全国高校毕业生人数795万,史上"更难就业季"大学生就业形势,再加上出国留学回来的约30万以及没有找到工作的往届毕业生,预计将有1000多万大学生同时竞争. 如果我们不是 ...
- /etc/shadow,/etc/passwd,/etc/shadow,/etc/passwd文件的内容解释
1.1 /etc/passwd文件内容格式 该目录存储的是操作系统用户信息,该文件为所有用户可见 用户名: 密码 : uid : gid :用户描述:主目录:登陆shell 举个 ...
- cobbler无人值守批量安装Linux系统
本文目录: 1.1 pxe安装系统 1.2 cobbler基本介绍 1.3 安装和配置cobbler 1.3.1 安装cobbler 1.3.2 配置dhcp和tftp 1.4 cobbler从本地光 ...