zoukankan      html  css  js  c++  java
  • PAT 1029队列

    #include<bits/stdc++.h>
    using namespace std;
    int main() {
        ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
        int n,m;
        long temp;
        queue<long> q1,q2;
        cin >> n;
        for(int i=0;i!=n;++i){
            cin >> temp;
            q1.push(temp);
        }
        cin >> m;
        int index = (n + m - 1) / 2,pos = 0;
        for(int i=0;i!=m;++i){
            cin >> temp;
            q2.push(temp);
            if(pos < index){
                if(!q1.empty() && q1.front() < temp)    q1.pop();
                else    q2.pop();
                ++pos;
            }
        }
        while(pos < index){
            if(q1.empty())
                q2.pop();
            else if(q2.empty())
                q1.pop();
            else{
                if(q1.front() < q2.front()) q1.pop();
                else    q2.pop();
            }
            ++pos;
        }
        if(q1.empty())
            cout << q2.front() << endl;
        else if(q2.empty())
            cout << q1.front() << endl;
        else
            cout << min(q1.front(),q2.front()) << endl;
    }
    

      

  • 相关阅读:
    Vue 中常见性能优化
    简单模板引擎实现
    函数柯理化
    url 解析
    快排
    防抖节流实现
    call、apply、bind 实现
    深克隆
    数组去重
    eventEmitter 简单实现
  • 原文地址:https://www.cnblogs.com/newstartCY/p/12628737.html
Copyright © 2011-2022 走看看