LA-3135 - Argus(优先队列)
3135 - Argus
  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 P eriod
Q num (0 < Qnum ≤ 3000) is query ID-number, and P eriod (0 < P eriod ≤ 3000) is the interval
between two consecutive returns of the result. After P eriod seconds of register, the result will be
returned for the first time, and after that, the result will be returned every P eriod 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 200
Register 2005 300
#
5
Sample Output
2004
2005
2004
2004
2005
题解:就是给你一系列事件,每隔一定时间会发生一次,然后让输出事件的发生,注意队列要想从小到大,应该是》。。。我咋说一直答案不对的;优先队列搞了下,ac了
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<stack>
using namespace std;
const int INF=0x3f3f3f3f;
#define mem(x,y) memset(x,y,sizeof(x))
#define SI(x) scanf("%d",&x)
#define SL(x) scanf("%lld",&x)
#define PI(x) printf("%d",x)
#define PL(x) printf("%lld",x)
#define P_ printf(" ")
#define T_T while(T--)
#define F(i,s,x) for(i=s;i<x;i++)
const double PI=acos(-1.0);
typedef long long LL;
struct Node{
int v,t,num;
Node(int v=0,int t=0,int num=1):v(v),t(t),num(num){}
friend bool operator < (Node a,Node b){
if(a.t*a.num!=b.t*b.num)return a.t*a.num>b.t*b.num;
else return a.v>b.v;
}
};
int main(){
char s[10];
Node a;
priority_queue<Node>dl;
while(scanf("%s",s),strcmp(s,"#")){
scanf("%d%d",&a.v,&a.t);
dl.push(a);
}
int x;
SI(x);
//while(!dl.empty())PI(dl.top().t*dl.top().num),P_,dl.pop();
while(x--){
a=dl.top();
dl.pop();
PI(a.v);puts("");
a.num++;
dl.push(a);
}
return 0;
}
LA-3135 - Argus(优先队列)的更多相关文章
- LA 3135 - Argus
		
看题:传送门 大意就是让你编写一个称为argus的系统,这个系统支持一个register的命令: Register Q_num Period 该命令注册了一个触发器,它每Period秒就会残生一个编 ...
 - 【暑假】[实用数据结构]UVAlive 3135 Argus
		
UVAlive 3135 Argus Argus Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %l ...
 - LA 3135 (优先队列) Argus
		
将多个有序表合并成一个有序表就是多路归并问题,可用优先队列来解决. #include <cstdio> #include <queue> using namespace std ...
 - LA 3135 阿格斯(优先队列)
		
https://vjudge.net/problem/UVALive-3135 题意: 你的任务是编写一个称为Argus的系统.该系统支持一个Register的命令 Register Q_num Pe ...
 - uva11997 K Smallest Sums&&UVALive 3135 Argus(优先队列,多路归并)
		
#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #inc ...
 - Argus UVALive - 3135(优先队列 水题一道)
		
有一系列的事件,它每Period秒钟就会产生编号为qNum的事件,你的任务是模拟出前k个事件,如果多个事件同时发生,先处理qNum小的事件 今天再看看数据结构.. #include <iostr ...
 - LA 3135 优先队列
		
题目大意:有若干命令,它有两个属性Q_Num,Period(周期).按时间循序模拟前k个命令并输出他们的Q_Num,若同时发生输出Q_Num最小的值. #include<iostream> ...
 - 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 ...
 
随机推荐
- python学习(序章)
			
好久没写过笔记了,最近听说写博客笔记能使知识记忆更深刻,于是就开始写写,不为推广,只为增加记忆.好了,开始python的学习: 学习一门语言的快慢,与人无关,主要是与学习的目的有关,python语言目 ...
 - Java关键字static
			
链接地址:http://www.cnblogs.com/devinzhang/archive/2011/12/13/2286367.html static表示“全局”或者“静态”的意思,用来修饰成员变 ...
 - 【转载】VC++中的图像类型转换--使用开源CxImage类库
			
一.CxImage类库简介 这只是翻译了CxImage开源项目主页上的部分简介及简单使用. CxImage类库是一个优秀的图像操作类库.它可以快捷地存取.显示.转换各种图像.有的读者可能说,有那么多优 ...
 - JSP——九大内置对象和其四大作用域
			
一.JSP九大内置对象: JSP根据Servlet API 规范提供了某些内置对象,开发者不用事先声明就可以使用标准的变量来访问这些对象. Request:代表的是来自客户端的请求,例如我们在FORM ...
 - css伪类伪元素
			
在CSS中,模式(pattern)匹配规则决定哪种样式规则应用于文档树(document tree)的哪个元素.这些模式叫着选择符(selector). 一条CSS规则(rule)是选择符{属性:值; ...
 - [转]  iOS多线程编程之NSOperation和NSOperationQueue的使用
			
<iOS多线程编程之NSThread的使用> 介绍三种多线程编程和NSThread的使用,这篇介绍NSOperation的使用. 使用 NSOperation的方式有两种, 一种是用定义好 ...
 - 名叫Florida的女孩问题
			
近读列纳德·蒙洛迪诺的<醉汉的脚步>,读到第六章,作者举了一个超级变态的例子来解释条件概率或者说是贝叶斯概率. 1.先来看一个简单点的问题:已知所有有2个孩子的家庭,其中一个家庭2个孩子都 ...
 - 无法启动此程序,因为计算机中丢失QtCore4.dll。尝试重新安装该程序以解决此问题(在系统里添加3个路径)
			
解决方法: 计算机-属性-高级系统设置-高级-环境变量-系统变量-Path 添加 E:\Qt\4.8.5\bin; E:\Qt\4.8.5\qmake; E:\mingw\bin 重启计算机 http ...
 - CodeIgniter结合Bootstrap
			
CodeIgniter-Bootstrap结合了 cI和bootstrap的长处,一个专注于服务器端,一个专注于ui,这个把2个结合起来了.框架地址: http://www.andyhawthorne ...
 - Shared_from_this 几个值得注意的地方
			
shared_from_this()是enable_shared_from_this<T>的成员 函数,返回shared_ptr<T>.首先需要注意的是,这个函数仅在share ...