4 条题解

  • 2
    @ 2024-9-29 11:56:07

    循环队列版题解

    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <queue>
    #define int long long
    using namespace std;
    int n;
     
    inline void solve()
    {
        int n;
        scanf ("%lld" , &n);
        queue<pair<int , int > > q;
        for (int i = 1 ; i <= n ; i ++ )
        {
            pair<int , int > temp;
     
            scanf("%lld" , &temp.first);
            temp.second = i;
     
            q.push(temp);
        }
          
        int num = 1;
        int king = 1;
        int m = q.front().first;
        while(!q.empty())
        {
            if (num == m)
            {
                if (king == n) 
                {
                    printf ("%lld" , q.front().second);
                    return ;
                }
                q.pop();
                num = 1;
                king ++;
                m = q.front().first;
            }
            else
            {
                q.push(q.front());
                q.pop();
                num ++;
            }
        }
        cout << endl;
          
    }
     
    signed main()
    {   
        solve();
        return 0;
    }
    

    信息

    ID
    5391
    时间
    3000ms
    内存
    256MiB
    难度
    1
    标签
    递交数
    33
    已通过
    3
    上传者