题解 | 小猫排队

小猫排队

https://www.nowcoder.com/practice/a88a85759a9b4c9c8dfd687c366ad5bf

#include<bits/stdc++.h>
using namespace std;
#define int long long
int n;
const int N=2e5+10;
int a[N];


signed main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    int time=0;
    int cute;
    cin>>cute;
    int pos=n+1;
    int exit=0;
    while(true)
    {
        int new_pos=pos;
        for(int i=pos-1;i>exit;i--)
        {
            if(a[i]>cute)
            {
                new_pos=i;
                break;
            }
        }
        if(pos==new_pos)
        {
            time+=(pos-exit);
            break;
        }
        pos=new_pos;
        if(exit+1==pos)
        {
            time++;
            break;
        }
        exit++;
        time++;
    }
    cout<<time<<endl;
    return 0;
}

全部评论

相关推荐

没有奇迹的世界:简直世另我 一样的先学后端再转前端一样的简历模板 绷不住了甚至描述都这么像 值得庆幸的是你才28届 加油
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务