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)递推. ...
随机推荐
- 日常-acm-三位数反转
输入一个三位数,分理出它的百位,十位和个位,反转后输出. 样例输入: 127 样例输出: 721 tips:注意最后一位为0的情况,如360,输出063 #include <iostream&g ...
- Problem T: 结构体--学生信息排序
Problem T: 结构体--学生信息排序 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 2219 Solved: 1305[Submit][Sta ...
- oracle 数据导到 sql server
方法一: navicate:用法比较简单,选择工具-数据传输就可以了.目前测试了下暂时没遇到什么问题. 方法二: Microsoft SQL Server Migration Assistant 8. ...
- FMDB中的数据处理
[self.db executeUpdate:@"create table test (a text, b text, c integer, d double, e double)" ...
- 【贪心 计数 倍增】bzoj4458: GTY的OJ
倍增写挂调了半个晚上 Description 身为IOI金牌的gtyzs有自己的一个OJ,名曰GOJ.GOJ上的题目可谓是高质量而又经典,他在他的OJ里面定义了一个树形的分类目录,且两个相同级别的目录 ...
- 【NOIP2017提高A组冲刺11.8】好文章
#include<algorithm> #include<iostream> #include<cstring> #include<cstdio> us ...
- CentOS7下systemd
配置文件: /usr/lib/systemd/system:每个服务最主要的启动脚本设置,类似于之前的/etc/init.d/ /run/systemd/system:系统执行过程中所产生的服务脚本, ...
- 零拷贝详解 Java NIO学习笔记四(零拷贝详解)
转 https://blog.csdn.net/u013096088/article/details/79122671 Java NIO学习笔记四(零拷贝详解) 2018年01月21日 20:20:5 ...
- ubuntu18.04+win10解决时钟不同步办法
安装ntpdate: 执行命令: sudo apt-get install ntpdate 设置校正服务器: sudo ntpdate time.windows.com 设置硬件时间为本地时间: 执行 ...
- Eclipse上进行java web项目的打包
以下是一个基于maven搭建的Spring Boot项目的目录结构 版权声明:本文为博主原创文章,未经博主允许不得转载. 原文地址: https://www.cnblogs.com/poterliu/ ...