题解:CF83B Doctor
题目传送门
题意
给定一个包含
现在请你执行
求最后的序列剩下的数的编号(若 -1)。
思路
这道题可以用队列做。如果大于 −1。
code
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,k,x,s;
queue<ll>que;
queue<ll>q;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin>>n>>k;
for(int i=1;i<=n;++i)
{
cin>>x;
que.push(x);
q.push(i);
}
for(int i=1;i<=k;++i)
{
if(que.empty())
{
cout<<-1<<endl;
return 0;
}
x=que.front(),s=q.front();
que.pop(),q.pop();
if(x-1>0)que.push(x),q.push(s);
}
while(!q.empty())
{
cout<<q.front()<<" ";
q.pop();
}
return 0;
}