zoukankan      html  css  js  c++  java
  • UVA 12100 Printer Queue

    题意:有一个打印队列,每个打印任务优先级为1-9,按如下规则打印:

    • 若队首优先级不是最高,则移到队尾;
    • 否则打印队首后,令其出队

    思路:简单的map与queue操作;

    #include<bits/stdc++.h>
    
    struct prtjob
    {
        int pos,pty;
    }job;
    
    int t,n,m,ans;
    int main(void)
    {
        scanf("%d",&t);
        while(t--)
        {
            queue<prtjob> q;
            map<int,int> mp;
            scanf("%d%d",&n,&m);
            for(int i=0;i<n;i++){
                scanf("%d",&job.pty);
                job.pos=i;
                q.push(job);
                mp[job.pty]++;
            }
            ans=0;
            while(!q.empty())
            {
                if(q.front().pty < mp.rbegin()->first)
                {
                    q.push(q.front());
                    q.pop();
                }
                else if(q.front().pos==m) break;
                else
                {
                    if (mp[q.front().pty] == 1) 
                        mp.erase(q.front().pty); 
                    else 
                        mp[q.front().pty] --;
                    q.pop(); 
                    ans ++;
                }
            }
            printf("%d
    ",ans+1);
        }
    
        return 0;
    }
  • 相关阅读:
    pymysql
    Mysql
    协程
    线程池
    线程 条件
    线程 事件
    线程
    requests
    Linux 时区不对的解决办法
    Linux 简单命令
  • 原文地址:https://www.cnblogs.com/jaszzz/p/13050853.html
Copyright © 2011-2022 走看看