zoukankan      html  css  js  c++  java
  • UVALive3135 UVA1203 POJ2051 ZOJ2212 Argus【优先队列】

    Time Limit: 1000MS   Memory Limit: 30000K
    Total Submissions: 11450   Accepted: 5545

    Description

    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 200
    Register 2005 300
    #
    5
    

    Sample Output

    2004
    2005
    2004
    2004
    2005
    

    Source


    Regionals 2004 >> Asia - Beijing


    问题链接UVALive3135 UVA1203 POJ2051 ZOJ2212 Argus

    问题简述每个用户注册一个ID号,并且有一个间隔时间。对于每个用户,每隔一个间隔时间打印一次。注册的用户到“#”为止。之后给出k,是需要打印的用户ID数量。

    问题分析用优先队列来解决是最合适的。

    程序说明:(略)

    题记:(略)

    参考链接:(略)


    AC的C++语言程序如下:

    /* UVALive3135 UVA1203 POJ2051 ZOJ2212 Argus */
    
    #include <iostream>
    #include <queue>
    
    using namespace std;
    
    struct _node {
        int num, period, cnt;
        bool operator <(_node a)const
        {
            if(cnt != a.cnt)
                return cnt > a.cnt;
            else
                return num > a.num;
        }
    };
    
    int main()
    {
        priority_queue<_node> q;
        _node t;
        string s;
        int k;
    
        while(cin >> s) {
            if(s == "#")
                break;
            else {
                cin >> t.num >> t.period;
                t.cnt = t.period;
                q.push(t);
            }
        }
    
        cin >> k;
        while(k--) {
            t = q.top();
            q.pop();
    
            cout << t.num << endl;
    
            t.cnt += t.period;
            q.push(t);
        }
    
        return 0;
    }




  • 相关阅读:
    AVL自平衡二叉树
    笔试+面试信息整理----面向笔试学习、面向面经编程
    传入值参数&传入引用参数的区别
    NLPIR智能挖掘实现行业大数据应用价值
    NLPIR大数据挖掘融合库、智、理三大先进理论技术
    NLPIR智能语义挖掘文本大数据深层意义
    NLPIR智能语义技术从采集到分析一步到位
    灵玖软件:NLPIR智能挖掘对文本数据精细化分析
    九眼合同智能审核系统运用NLPIR大数据技术进行核查
    NLPIR九眼智能审核平台助合同文本深度核查
  • 原文地址:https://www.cnblogs.com/tigerisland/p/7563574.html
Copyright © 2011-2022 走看看