• poj 2051 Argus(优先队列)


    题目链接: http://poj.org/problem?id=2051

    思路分析:

    优先级问题,使用优先队列求解;当执行某个任务后,再增加一个任务到队列中,

    该任务的优先级为执行任务的时间加上其时间间隔,如此反复直到求出前K个执行任务。

    代码:

    #include <iostream>
    #include <queue>
    using namespace std;
    
    struct Argu
    {
        int QNum;
        int period;
        int time;
        bool operator<(const Argu &rhs) const
        {
            if (time > rhs.time)
                return true;
            if (time == rhs.time)
                return QNum > rhs.QNum;
            return false;
        }
    };
    
    int main()
    {
        int k;
        char tmp[10];
        priority_queue<Argu> heap;
    
        while (scanf("%s", tmp) != EOF && strcmp(tmp, "#") != 0)
        {
            Argu command;
    
            scanf("%d%d", &command.QNum, &command.period);
            command.time = command.period;
            heap.push(command);
        }
    
        scanf("%d", &k);
        for (int i = 0; i < k; ++i)
        {
            Argu ans;
    
            ans = heap.top();
            heap.pop();
            ans.time += ans.period;
            heap.push(ans);
            printf("%d
    ", ans.QNum);
        }
    
        return 0;
    }
  • 相关阅读:
    赔了多少钱
    datatables使用
    Django开发汇总
    STF的DOCKER搭建
    ubuntu基本
    python 列表、元组、字典、字符串
    Appium环境搭建
    AppCrawler环境搭建
    TASK 总结
    python & jira
  • 原文地址:https://www.cnblogs.com/tallisHe/p/4263265.html
Copyright © 2020-2023  润新知