LA 3135 - Argus
来源:互联网 发布:最基本的网络通信协议 编辑:程序博客网 时间:2024/05/09 23:03
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 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 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 200Register 2005 300#5
Sample Output
20042005200420042005
优先队列的使用,实在是妙
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<vector>
#include<cmath>
#include<stdlib.h>
#include<iomanip>
#include<list>
#include<deque>
#include<map>
#include <stdio.h>
#include <queue>
#define maxn 10000+5
#define ull unsigned long long
#define ll long long
#define reP(i,n) for(i=1;i<=n;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define cle(a) memset(a,0,sizeof(a))
#define mod 90001
#define PI 3.141592657
#define INF 1<<30
const ull inf = 1LL << 61;
const double eps=1e-5;
using namespace std;
bool cmp(int a,int b){
return a>b;
}
struct Item
{
int Time,Qnum,Period;///Time是用来存时间的
///优先级比较函数,优先级高的先出队
bool operator< (const Item& a)const {///const必不可少
return Time>a.Time||(Time==a.Time&&Qnum>a.Qnum);
}
};
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
priority_queue<Item>pq;
char s[20];
while(cin>>s&&s[0]!='#')
{
Item item;
scanf("%d%d",&item.Qnum,&item.Period);
item.Time=item.Period;
pq.push(item);
}
int k;
cin>>k;
while(k--)
{
Item r=pq.top();pq.pop();
printf("%d\n",r.Qnum);
r.Time+=r.Period;
pq.push(r);
}
return 0;
}
- LA - 3135 - Argus
- LA - 3135 - Argus
- LA 3135 - Argus
- LA 3135 Argus
- LA 3135 argus
- LA 3135 Argus
- LA 3135(p188)----Argus
- LA 3135 - Argus
- LA 3135Argus
- LA 3135 Argus
- LA 3135 argus(优先队列)
- la 3135 Argus Data Structure
- LA 3135 Argus 优先队列
- Argus , Beijing 2004 ,LA 3135
- LA 3135 Argus ( 优先队列 )
- La 3435 argus
- 优先队列 阿格斯(Argus Beijing La 3135)
- LA 3135 Argus (2004北京 模拟系统调度 优先队列实现)
- 用while随机求十个数的和
- HDU 1506Largest Rectangle in a Histogram
- UVA 11991Easy Problem from Rujia Liu?
- solr添加IKAnalyzer分词器
- UVA 11995I Can Guess the Data Structure!
- LA 3135 - Argus
- 栈,队列,优先队列的使用
- 链队列的综合操作(详解、演示)C语言实现
- Redis主从备份以及key的过期时间配置
- vector的用法
- 后缀表达式+栈的应用=四则表达式运算
- 单链表的实现
- C#控制台实现52张扑克牌的分法
- 循环链表实现队列