• PAT (Advanced Level) 1014. Waiting in Line (30)


    简单模拟题。

    #include<iostream>
    #include<cstring>
    #include<cmath>
    #include<algorithm>
    #include<cstdio>
    #include<map>
    #include<queue>
    using namespace std;
    
    struct X
    {
        int st;
        int len;
        int en;
    }p[1500];
    queue<int>Q[25];
    int n,m,k,s;
    
    bool check()
    {
        for(int i=1;i<=n;i++)
            if(!Q[i].empty()) return 1;
        return 0;
    }
    
    int main()
    {
        scanf("%d%d%d%d",&n,&m,&k,&s);
        for(int i=1;i<=k;i++) scanf("%d",&p[i].len);
        int pos;
        for(pos=1;pos<=min(k,n);pos++) { p[pos].st=480; Q[pos].push(pos); }
        for(;pos<=min(n*m,k);pos++)
        {
            int id=pos%n; if(id==0) id=n;
            Q[id].push(pos);
        }
        while(1)
        {
            if(check()==0) break;
            int Min=999999;
            for(int i=1;i<=n;i++)
            {
                if(Q[i].empty()) continue;
                int id=Q[i].front();
                Min=min(Min,p[id].st+p[id].len);
            }
    
            for(int i=1;i<=n;i++)
            {
                if(Q[i].empty()) continue;
                int id=Q[i].front();
                if(p[id].st+p[id].len==Min)
                {
                    p[id].en=p[id].st+p[id].len;
                    Q[i].pop();
                    if(pos<=k) Q[i].push(pos++);
                    if(!Q[i].empty()) p[Q[i].front()].st=p[id].en;
                }
            }
        }
        for(int i=1;i<=s;i++)
        {
            int id; scanf("%d",&id);
            if(p[id].st/60>=17) printf("Sorry
    ");
            else printf("%02d:%02d
    ",p[id].en/60,p[id].en%60);
        }
        return 0;
    }
  • 相关阅读:
    codeforces689A
    codeforces222A
    codeforces553A
    2021牛客国庆集训派对day6 J
    SVM--支持向量机
    压缩感知
    范数
    LeNet详解
    卷积神经网络(CNN)详解
    BP算法实例—鸢尾花的分类(Python)
  • 原文地址:https://www.cnblogs.com/zufezzt/p/5497207.html
Copyright © 2020-2023  润新知