zoukankan      html  css  js  c++  java
  • 打印队列 UVA12100

    打印队列

    UVA12100打印队列


    
    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        int t;
        cin >> t;
        while (t--)
        {
            queue<int> q;
            priority_queue<int> pq;
            int n,m,s;
            cin >> n >> m;
            for (int i=0;i<n;i++)
            {
                cin >> s;
                q.push(s);pq.push(s);
            }
            int x = 0;
            while (true)
            {
                if (q.front() == pq.top())
                {
                    if (x == m)
                    {
                        cout << n - q.size() + 1 << endl;
                        break;
                    }
                    else
                    {
                        q.pop();pq.pop();
                        x++;
                    }
                    
                }
                else
                {
                    int t = q.front();
                    q.pop();q.push(t);
                    if (x == m)
                    {
                        x = 0;
                        m = q.size() - 1;
                    }
                    else
                        x++;
                    
                }
                
            }
            
        }
        return 0;
    }
    
    
    

    总结

    1. 需要用队列+优先队列模拟
    2. 需要处理一些特殊情况.
  • 相关阅读:
    一站式示例代码库登陆微软中国首页
    一站式示例代码库 中文版 2010年10月更新
    微软一站式示例代码库20101010 新增代码示例简介
    一站式示例代码库 中文版 2010年9月更新
    微软全新示例代码请求服务正式上线
    Merge Sort 归并排序
    递归的Fibonacci在数羊
    VS2010 常用快捷键总结
    【总结——HTTP协议】
    在项目中使用log4net记录日志
  • 原文地址:https://www.cnblogs.com/ssorryqaq/p/10342384.html
Copyright © 2011-2022 走看看