POJ 2051 Argus
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 8782 | Accepted: 3985 |
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
题目大意:输入一串用户的命令,id,周期,没过一个周期输出一次id,输入以“#”结束,最后一行输入一个整数n,表示打印n个用户id。
解题方法:堆排序,用最小堆,每次将时间值最小的放到堆顶,然后输出,加上时间周期之后在进行堆调制,重复n次即可。
#include <stdio.h>
#include <iostream>
#include <string.h>
using namespace std; typedef struct
{
int time;
int period;
int id;
}Node; Node user[]; void sift(int low, int high)
{
int i = low;
int j = * i;
Node temp = user[i];
while(j <= high)
{
if (j < high && (user[j].time > user[j + ].time || (user[j].time == user[j + ].time && user[j].id > user[j + ].id)))
{
j++;
}
if (temp.time > user[j].time || (temp.time == user[j].time && temp.id > user[j].id))
{
user[i].id = user[j].id;
user[i].period = user[j].period;
user[i].time = user[j].time;
i = j;
j = i * ;
}
else
{
break;
}
}
user[i] = temp;
} int main()
{
char cmd[];
int id, period, n;
int nCount = ;
while(true)
{
cin>>cmd;
if (strcmp(cmd, "#") == )
{
break;
}
cin>>id>>period;
user[++nCount].id = id;
user[nCount].period = period;
user[nCount].time = period;
}
cin>>n;
while(n--)
{
for (int i = nCount / ; i >= ; i--)
{
sift(i, nCount);
}
user[].time += user[].period;
cout<<user[].id<<endl;
}
return ;
}
POJ 2051 Argus的更多相关文章
- poj 2051.Argus 解题报告
题目链接:http://poj.org/problem?id=2051 题目意思:题目有点难理解,所以结合这幅图来说吧---- 有一个叫Argus的系统,该系统支持一个 Register 命令,输入就 ...
- poj 2051 Argus(优先队列)
题目链接: http://poj.org/problem?id=2051 思路分析: 优先级问题,使用优先队列求解:当执行某个任务后,再增加一个任务到队列中, 该任务的优先级为执行任务的时间加上其时间 ...
- POJ 2051 argus(简单题,堆排序or优先队列)
又是一道数据结构题,使用堆来进行权值调整和排序,每次调整都是o(n)的复杂度,非常高效. 第一眼看题觉得可以用优先队列来做,应该也很简单. 事实上多数优先队列都是通过堆来实现的. 写的时候还是出了一些 ...
- 算法手记 之 数据结构(堆)(POJ 2051)
一篇读书笔记 书籍简评:<ACM/ICPC 算法训练教程>这本书是余立功主编的,代码来自南京理工大学ACM集训队代码库,所以小编看过之后发现确实很实用,适合集训的时候刷题啊~~,当时是听了 ...
- POJ 2051
http://poj.org/problem?id=2051 这个题目的大题意思就是给你一些ID,和ID所对应的周期,每隔它所对应的周期,它的任务就会执行,就会输出所对应的ID Register 20 ...
- 最小堆的维护,POJ(2051)
题目链接:http://poj.org/problem?id=2051 ///维持最小堆(优先队列)POJ2051 #include <iostream> #include <str ...
- 优先队列(priority_queue)的cmp,POJ(2051)
sort()函数的cmp为函数,priority_queue的cmp为类,具体写法是: struct Node { int i,j; } node[]; struct cmp { bool opera ...
- POJ 题目分类(转载)
Log 2016-3-21 网上找的POJ分类,来源已经不清楚了.百度能百度到一大把.贴一份在博客上,鞭策自己刷题,不能偷懒!! 初期: 一.基本算法: (1)枚举. (poj1753,poj2965 ...
- (转)POJ题目分类
初期:一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. (4)递推. ...
随机推荐
- dataset datatable datacolums datarow
DataSet 表示数据在内存中的缓存. 属性 Tables 获取包含在 DataSet 中的表的集合. ds.Tables["sjxx"] DataTable 表示内存中数据的 ...
- 洛谷 P2827 蚯蚓
题目描述 本题中,我们将用符号\lfloor c \rfloor⌊c⌋表示对c向下取整,例如:\lfloor 3.0 \rfloor= \lfloor 3.1 \rfloor=\lfloor 3.9 ...
- UWP开发:自动生成迷宫&自动寻路算法(2)
之后我们编写一个类,同时创建一个List,将List与前端的Rectangle绑定. public static List<Rect> Rects { get; set; }Rects = ...
- SAP CRM Survey调查问卷的存储模型
数据库表CRM_SVY_DB_SVS,通过如下的函数CRM_SVY_DB_SVS_CREATE插入: 可以通过指定的创建者和创建时间很容易查找到特定的Survey: 调查问卷的答案明细以XML的格式存 ...
- 问题驱动的Git学习
(搬运自我在SegmentFault的博客) 本人是个Git新手,平时用Git最多的就是push,因为别的都不怎么会用.这几天因为在小组中负责代码的整合,顺便将代码提交到Github,接触到了Git更 ...
- HDU 5489 Removed Interval 2015 ACM/ICPC Asia Regional Hefei Online (LIS变形)
定义f[i]表示以i为开头往后的最长上升子序列,d[i]表示以i为结尾的最长上升子序列. 先nlogn算出f[i], 从i-L开始枚举f[i],表示假设i在最终的LIS中,往[0,i-L)里找到满足a ...
- C++11 function用法 可调用对象模板类
std::function<datatype()> ()内写参数类型 datatype 代表function的返回值 灵活的用法.. 代码如下 #include <stdio.h&g ...
- 爬虫3_python2
# coding=utf-8 import urllib params=urllib.urlencode({'t':1,'eggs':2,'bacon':0})#现在大多数网站都是动态网页,需要你动态 ...
- GCD之dispatch queue
GCD之dispatch queue iOS中多线程编程工具主要有: NSThread NSOperation GCD 这三种方法都简单易用,各有千秋.但无疑GCD是最有诱惑力的,因为其本身是appl ...
- 201621123080《java程序设计》第14周实验总结
201621123080<java程序设计>第14周实验总结 1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结与数据库相关内容. 2. 使用数据库技术改造你的系统 2. ...