zoukankan      html  css  js  c++  java
  • [Luogu P2278] [HNOI2003]操作系统

    题面

    传送门:https://www.luogu.org/problemnew/show/P2278


    Solutiton

    挺简单的一道模拟题,拿堆模拟一下题目意思就好

    堆中有两个关键字,分别是优先级和到达时间

    还要维护一下每个任务剩余时间(还有多久完成)

    因为堆不能直接改.得在堆里记录编号然后映射出来

    这里总结一下要注意的细节:

    1.在下一个任务到达之前,尽可能把CPU内的任务完成了

    2.注意读入

    3.注意注释文件读写233(我因为这破事爆零一次)

    4.没了

    好像不需要记录到达时间,编号即为到达时间先后

    但懒得改了


     Code

    //Luogu P2278 [HNOI2003]操作系统
    //May,4th,2018
    //堆+模拟
    #include<iostream>
    #include<cstdio>
    #include<queue>
    using namespace std;
    const int N=1000000;
    int t[N];
    struct op
    {
        int a,no,at;
        friend bool operator < (op A,op B)
        {
            if(A.a==B.a)
                return A.at > B.at;
            return A.a < B.a;
        }
    };
    priority_queue <op,vector<op> > d;
    int main()
    {
        //freopen("system.in","r",stdin);
        int no,at,T,a,t_now=0;
        while(scanf("%d%d%d%d",&no,&at,&T,&a)==4)
        {
            while(d.empty()==false)
            {
                op now=d.top();
                if(t[now.no]<=at-t_now)
                {
                    d.pop();
                    t_now+=t[now.no];
                    printf("%d %d
    ",now.no,t_now);
                }
                else
                {
                    t[now.no]-=at-t_now;
                    break;
                }
            }
            op temp;
            temp.no=no,temp.a=a,temp.at=at,t[no]=T;
            d.push(temp);
            t_now=at;
        }
        
        while(d.empty()==false)
        {
            op now=d.top();
            d.pop();
            t_now+=t[now.no];
            printf("%d %d
    ",now.no,t_now);
        }
        return 0;
    }
    自己选择的路,跪着也要走完。朋友们,虽然这个世界日益浮躁起来,只要能够为了当时纯粹的梦想和感动坚持努力下去,不管其它人怎么样,我们也能够保持自己的本色走下去。
  • 相关阅读:
    606. Construct String from Binary Tree
    696. Count Binary Substrings
    POJ 3255 Roadblocks (次短路)
    POJ 2823 Sliding Window (单调队列)
    POJ 1704 Georgia and Bob (博弈)
    UVa 1663 Purifying Machine (二分匹配)
    UVa 10801 Lift Hopping (Dijkstra)
    POJ 3281 Dining (网络流之最大流)
    UVa 11100 The Trip, 2007 (题意+贪心)
    UVaLive 4254 Processor (二分+优先队列)
  • 原文地址:https://www.cnblogs.com/GoldenPotato/p/8990066.html
Copyright © 2011-2022 走看看