跳到正文

题解

CF83B 题解

XXh0919约 1 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年7月15日
篇幅
约 1 分钟
获赞
1
题目
CF83B

版本

  1. v1当前

纯属队列训练题

这题其实说的很明白,就是让你在 nn 个数里拿出第一个数,若这个数减 11 不为零就将其放到队尾,否则将其弹出去,在 kk 次操作后输出剩下所有数的编号,若操作次数大于 kk 次,则输出 −1-1。

你们最爱的代码:

C++
#include<bits/stdc++.h>
using namespace std;
long long n,k,x,s;
queue<long long>que;
queue<long long>hao;
int main()
{
    cin>>n>>k;
    for(int i=1;i<=n;++i)
    {
    	cin>>x;
    	que.push(x);//输入
    	hao.push(i);//编号
	}
	for(int i=1;i<=k;++i)
    {
    	if(que.empty())//若队列为空
    	{
    		cout<<-1<<endl;//直接带走
    		return 0;
		}
    	x=que.front(),s=hao.front();
    	que.pop(),hao.pop();//先让第一个数“退休”
    	if(x-1>0)//若还没有到退休的时候(打个比方)
        que.push(x),hao.push(s);//快点回来上班儿
	}
	while(!hao.empty())//输出
	{
		cout<<hao.front()<<' ';
		hao.pop();
	}
    return 0;
}

管理员求过!!!!!!!

原文