• UVa 12100


    题意

    排队打印。每个打印任务有自己的优先级1~9,数字越大优先级越高。每个打印任务需要1分钟,如果队首后面有优先级更高的打印任务,则队首站到队尾,直到队首为队列中最高优先级的任务,则打印。

    思路

    水题
    操作用STL队列queue
    用mrk[10]分别记录1~9优先级任务各自有多少
    每次查找队中最大优先级的级别,并循环判断

    AC代码

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <queue>
    
    using namespace std;
    const int maxn = 100 + 50;
    
    queue<int> q;
    int mrk[10], star[maxn];
    
    int main()
    {
        int T, n, m, i, time, st;
        cin >> T;
        while(T--)
        {
            memset(star,0,sizeof(star));
            memset(mrk,0,sizeof(mrk));
            time = 0;
            cin >> n >> m;
            for( i = 0; i < n; i++ ){
                q.push(i);
                cin >> st;
                star[i] = st;
                mrk[st]++;
            }
            for(;;){
                int imp;
                bool flag = false;
                for( i = 9; i >= 1; i-- )
                    if( mrk[i] != 0 )
                        break;
                imp = i;
                while( mrk[imp] ){
                    if( star[q.front()] != imp ){
                        q.push(q.front());
                        q.pop();
                    }
                    else{
                        time++;
                        if( q.front() == m ){
                            flag = true;
                            break;
                        }
                        q.pop();
                        mrk[imp]--;
                    }
                }
                if( flag ){
                    cout << time << endl;
                    break;
                }
            }
            while( !q.empty() )
                q.pop();
        }
        return 0;
    }
    
  • 相关阅读:
    细说Cookie(转)
    Custom Exception in ASP.NET Web API 2 with Custom HttpResponse Message
    内核中的定时器
    ibus拼音安装_ubuntu10.04
    linux模块
    zebra/quagga线程分析
    vim常用配置
    rar安装和使用
    zebra/quagga
    netsnmp编译动态库
  • 原文地址:https://www.cnblogs.com/JinxiSui/p/9740631.html
Copyright © 2020-2023  润新知