蒟蒻的题解

071maozihan 2022-04-16 8:53:34 4 返回题目

题目思路

————————————————————

这就是一道模拟题,顺着题目的意思去模拟就行了

而且这道题也非常的友好,数据量很小,不需要优化

纯模拟就完事了

因为是模拟题,所以代码没有加注释,请见谅~~~~~~~

————————————————————

下面是AC代码:

#include<bits/stdc++.h>

#define int long long

const long long maxn=1e4+10;

using namespace std;

int n,m;

int a[maxn];

queue q,tmp;

signed main()

{

cin>>n>>m;

for(int i=1;i<=n;i++){

	cin>>a[i];

}

for(int i=1;i<=m;i++){

	q.push(a[i]);

}

int d=m;

int ans=0;

while(!q.empty()){

	while(!q.empty()){

		int u=q.front();

		q.pop();

		if(u == 1){

			if(d+1<=n)tmp.push(a[d+1]);

			d++;

		}

		else tmp.push(u-1);

	}

	while(!tmp.empty()){

		int u=tmp.front();

		q.push(u);

		tmp.pop();

	}

	ans++;

}

cout<<ans;

return 0;

}

{{ vote && vote.total.up }}