原题链接:https://vjudge.net/problem/UVA-12100
分类:<vector>
备注:水题
代码如下:
#include<cstdio>
#include<vector>
using namespace std;
int main(void)
{
int T;
scanf("%d", &T);
while (T--)
{
int n, pos;
vector<int>q;
scanf("%d%d", &n, &pos);
for (int i = 0; i < n; i++)
{
int x; scanf("%d", &x);
q.push_back(x);
}
int cnt = 0;
while (1)
{
cnt++;
while (1)
{
int head = q[0], flag = 1;
for (int i = 1; i < q.size(); i++)
if (q[i] > head)
{
q.push_back(head);
q.erase(q.begin());
if (pos == 0)pos = q.size() - 1;
else pos--;
flag = 0;
break;
}
if (flag) { q.erase(q.begin()); pos--; break; }
}
if (pos == -1)break;
}
printf("%d\n", cnt);
}
return 0;
}