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了

代码:

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<cmath>
  5. #include<algorithm>
  6. #include<queue>
  7. #include<vector>
  8. #include<stack>
  9. using namespace std;
  10. const int INF=0x3f3f3f3f;
  11. #define mem(x,y) memset(x,y,sizeof(x))
  12. #define SI(x) scanf("%d",&x)
  13. #define SL(x) scanf("%lld",&x)
  14. #define PI(x) printf("%d",x)
  15. #define PL(x) printf("%lld",x)
  16. #define P_ printf(" ")
  17. #define T_T while(T--)
  18. #define F(i,s,x) for(i=s;i<x;i++)
  19. const double PI=acos(-1.0);
  20. typedef long long LL;
  21. struct Node{
  22. int v,t,num;
  23. Node(int v=0,int t=0,int num=1):v(v),t(t),num(num){}
  24. friend bool operator < (Node a,Node b){
  25. if(a.t*a.num!=b.t*b.num)return a.t*a.num>b.t*b.num;
  26. else return a.v>b.v;
  27. }
  28. };
  29. int main(){
  30. char s[10];
  31. Node a;
  32. priority_queue<Node>dl;
  33. while(scanf("%s",s),strcmp(s,"#")){
  34. scanf("%d%d",&a.v,&a.t);
  35. dl.push(a);
  36. }
  37. int x;
  38. SI(x);
  39. //while(!dl.empty())PI(dl.top().t*dl.top().num),P_,dl.pop();
  40. while(x--){
  41. a=dl.top();
  42. dl.pop();
  43. PI(a.v);puts("");
  44. a.num++;
  45. dl.push(a);
  46. }
  47. return 0;
  48. }

  

LA-3135 - Argus(优先队列)的更多相关文章

  1. LA 3135 - Argus

    看题:传送门 大意就是让你编写一个称为argus的系统,这个系统支持一个register的命令: Register  Q_num Period 该命令注册了一个触发器,它每Period秒就会残生一个编 ...

  2. 【暑假】[实用数据结构]UVAlive 3135 Argus

    UVAlive 3135 Argus Argus Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %l ...

  3. LA 3135 (优先队列) Argus

    将多个有序表合并成一个有序表就是多路归并问题,可用优先队列来解决. #include <cstdio> #include <queue> using namespace std ...

  4. LA 3135 阿格斯(优先队列)

    https://vjudge.net/problem/UVALive-3135 题意: 你的任务是编写一个称为Argus的系统.该系统支持一个Register的命令 Register Q_num Pe ...

  5. uva11997 K Smallest Sums&&UVALive 3135 Argus(优先队列,多路归并)

    #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #inc ...

  6. Argus UVALive - 3135(优先队列 水题一道)

    有一系列的事件,它每Period秒钟就会产生编号为qNum的事件,你的任务是模拟出前k个事件,如果多个事件同时发生,先处理qNum小的事件 今天再看看数据结构.. #include <iostr ...

  7. LA 3135 优先队列

    题目大意:有若干命令,它有两个属性Q_Num,Period(周期).按时间循序模拟前k个命令并输出他们的Q_Num,若同时发生输出Q_Num最小的值. #include<iostream> ...

  8. UVA 1203 - Argus(优先队列)

    UVA 1203 - Argus 题目链接 题意:给定一些注冊命令.表示每隔时间t,运行一次编号num的指令.注冊命令结束后.给定k.输出前k个运行顺序 思路:用优先队列去搞,任务时间作为优先级.每次 ...

  9. uva 1203 - Argus(优先队列)

    option=com_onlinejudge&Itemid=8&page=show_problem&problem=3644" target="_blank ...

随机推荐

  1. 2.Freshman阶段学习内容的确定

    我刷知乎.在知乎上答题的程序员,不是很牛逼就是更牛逼,说起各种系统.各种系统的各种版本.各种语言.数据库.算法.IT届的各种圣战都有板有眼.信手拈来.头头是道,不得不服.这导致了一些非常严重的问题:我 ...

  2. Java中this和super的用法总结

    这几天看到类在继承时会用到this和super,这里就做了一点总结,与各位共同交流,有错误请各位指正~ this this是自身的一个对象,代表对象本身,可以理解为:指向对象本身的一个指针. this ...

  3. ##DAY5 UIControl及其子类

    ##DAY5 UIControl及其子类 #pragma mark ———————UIControl——————————— UIControl初识: 1)UIControl是有控制功能的视图(比如UI ...

  4. C part 1 -- 指令篇

    Windows系统的cmd(command命令行工具): Shutdown -s -t 600:表示600秒后自动关机 Shutdown -a :可取消定时关机 Shutdown -r -t 600: ...

  5. Android 开发笔记“调用.net webservice遇到的问题”

    1.An exception occurred: org.ksoap2.SoapFault SoapFault - faultcode: 'soap:Server' faultstring: '服务器 ...

  6. bzoj 1047 : [HAOI2007]理想的正方形 单调队列dp

    题目链接 1047: [HAOI2007]理想的正方形 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2369  Solved: 1266[Submi ...

  7. A Byte of Python (1)安装和运行

    有两种方式构建软件设计:一种是把软件做得很简单以至于明显找不到缺陷:另一种是把它做得很复杂以至于找不到明显的缺陷. ——C.A.R. Hoare 获得人生中的成功需要的专注与坚持不懈多过天才与机会. ...

  8. xp的停止更新对我们有什么影响?

    微软与2001年推出windows xp系统,这款系统的成功毋庸置疑,但由于太过成功,微软在随后推出的vista系统和win7系统普及起来却异常困难.大多数人已经习惯了xp的操作,再加上一批铁杆旧电脑 ...

  9. DB2 权限控制

    http://blog.csdn.net/liujinwei2005/article/details/8606983 http://www.ibm.com/developerworks/cn/data ...

  10. Delphi函数指针的两种定义(对象方法存在一个隐藏参数self,所以不能相互赋值)

    delphi中经常见到以下两种定义 Type TMouseProc = procedure (X,Y:integer); TMouseEvent = procedure (X,Y:integer) o ...