• 操作系统(模拟题,HNOI2003)


    题意

    输入输出

    思路

    用优先队列维护等待进程,同时用两个变量分别维护当前时间和当前进程。
    每当一个新进程到来时,看看再其到来之前,又有哪些进程执行完毕。
    然后再与当前优先级最高的进程比较优先级,进行简单的分类讨论。
    最后不要忘记,所有进程都进来之后,再将他们从优先队列中弹出,直到优先队列为空为止。

    代码

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <queue>
    
    using namespace std;
    
    struct Process
    {
        int id, gettime, exetime, importance;
        int starttime;
        
        bool operator < (const Process &p) const
        {
            if(importance != p.importance) return importance < p.importance;
            return gettime > p.gettime;
        }
    };
    
    typedef struct Process process;
    
    int main()
    {
        int a, b, c, d;
        priority_queue<process> heap;
        int time = 0;
        scanf("%d%d%d%d", &a, &b, &c, &d);
        process p = {a, b, c, d, b};
        process tmp = p;
        heap.push(p);
        while(~scanf("%d%d%d%d", &a, &b, &c, &d)) {
            process p = {a, b, c, d};
            while(heap.size() && tmp.starttime + tmp.exetime <= p.gettime) {
                printf("%d %d
    ", tmp.id, tmp.starttime + tmp.exetime);
                int t = tmp.starttime + tmp.exetime;
                heap.pop();
                if(heap.size()) {
                    tmp = heap.top();
                    tmp.starttime = t;
                }
            }
            if(heap.size()) {
                tmp.exetime -= p.gettime - tmp.starttime;
                tmp.starttime = p.gettime;
            }
            time = p.gettime;
            if(!heap.size()) {
                p.starttime = time;
                heap.push(p);
                tmp = p;
                continue;
            }
            if(p < tmp) {
                heap.push(p);
                tmp.exetime -= time - tmp.starttime;
                tmp.starttime = time;
                heap.pop();
                heap.push(tmp);
            }
            else {
                tmp.exetime -= time - tmp.starttime;
                heap.pop();
                heap.push(tmp);
                p.starttime = time;
                heap.push(p);
                tmp = p;
            }
        }
        while(heap.size()) {
            tmp = heap.top();
            tmp.starttime = time;
            printf("%d %d
    ", tmp.id, tmp.starttime + tmp.exetime);
            time = tmp.starttime + tmp.exetime;
            heap.pop();
        }
        return 0;
    }
    
  • 相关阅读:
    激活函数(ReLU, Swish, Maxout)
    损失函数
    md5sum命令行使用注意事项
    Jetson ARM SeetaFace编译
    Linux下的wine生活(QQ/微信/Office)
    人脸识别引擎SeetaFace编译 ubuntu
    Python为8bit深度图像应用color map
    MySQL、MongoDB、Redis数据库Docker镜像制作
    bash的管道符与重定向
    Docker 及 nvidia-docker 使用
  • 原文地址:https://www.cnblogs.com/miraclepbc/p/14370949.html
Copyright © 2020-2023  润新知