zoukankan      html  css  js  c++  java
  • C

    C - Valeriy and Deque

    注意:vector<pair(int,int)> v;

    放入元素:v.push_back(make_pair(a,b))

    取元素:v[i].first,v[i].second.

    #include<bits/stdc++.h>
    using namespace std;
    const int maxn=1e5+10;
    queue<int> q;
    vector<pair<int,int>> v1;
    vector<pair<int,int>> v2;
    #define ll long long
    int main()
    {
        int n,tt;
        scanf("%d%d",&n,&tt);
        int maxx=-0x3f3f3f3f;
        for(int i=1; i<=n; i++)
        {
            int t;
            scanf("%d",&t);
            maxx=max(maxx,t);
            q.push(t);
        }
        int cnt1=0;
        int f=q.front();
        q.pop();
    //    printf("%d",maxx);
        while(q.size())
        {
            int t=q.front();
            q.pop();
    //        printf("???");
            v1.push_back(make_pair(f,t));
            if(f>t)
            {
                q.push(t);
    //            continue;
            }
            else
            {
                int temp=f;
                f=t;
                q.push(temp);
            }
    //        printf("%d %d
    ",f,maxx);
            if(f==maxx)
            {
                break;
            }
        }
        for(int i=1; i<=n-1; i++)
        {
            int t=q.front();
            q.pop();
            v2.push_back(make_pair(f,t));
            q.push(t);
        }
        while(tt--)
        {
            ll t;
            scanf("%lld",&t);
            if(t<=v1.size())
            {
                printf("%d %d
    ",v1[t-1].first,v1[t-1].second);
                continue;
            }
            else
                t-=v1.size();
            t=t%v2.size();
            if(t==0) t=v2.size();
            printf("%d %d
    ",v2[t-1].first,v2[t-1].second);
        }
    }
    
    //3 2
    //1000000 999999 999998
    //98
    //999999999999
  • 相关阅读:
    作用域链及作用域面试题
    this在js中的作用
    dom对象
    作用域问题
    逻辑运算
    socket.io 的使用
    mongoDB 的使用
    使用 usb 调试的时候,连接上电脑没反应
    uni-app 的更新及碰到的问题
    WebSocket 的使用
  • 原文地址:https://www.cnblogs.com/dongdong25800/p/11084377.html
Copyright © 2011-2022 走看看