之前遗留的一道问题,只需要把自己需要打印的文件位置不停的更新,同时更新最大值就能做出来,更像是一道借助stl实现的模拟
很多时候不是做不出来,而是真的懒得去更进一步的思考,哎,这道题之前没认真想,现在开始训练回暖一下,这一个多月没碰C++有点生疏了,其实还是想学matlab和py,还想学java,一点点来吧。我又回来了。。
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<time.h>
using namespace std;
int main()
{
int t;
scanf("%d",&t);
while(t --)
{
int pos, n;
scanf("%d%d",&n,&pos);
int a[105];
queue<int>q;
for(int i = 0; i < n; i ++){
scanf("%d",&a[i]);
q.push(a[i]);
}
int now = n - 1;
sort(a, a + n);
int maxy = a[now];
int tot = 0;
while(! q.empty())
{
int h = q.front();
if(h == maxy)
{
tot ++;
if(pos == 0) break;
now --;
maxy = a[now];
pos --;
q.pop();
}
else
{
q.pop();
q.push(h);
pos --;
if(pos < 0)
pos = n - 1 - tot;
}
}
printf("%d\n",tot);
}
return 0;
}