poj3125
简单题
View Code
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
#define maxn 105
int n, m;
int f[maxn];
int g[maxn];
bool vis[maxn];
void input()
{
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++)
scanf("%d", &f[i]);
memcpy(g, f, sizeof(g));
}
void work()
{
int ans = 0;
memset(vis, 0, sizeof(vis));
int pos = 0;
int i = n - 1;
while (!vis[m])
{
while (f[pos % n] != g[i])
pos++;
pos %= n;
vis[pos] = true;
i--;
ans++;
pos++;
}
printf("%d\n", ans);
}
int main()
{
//freopen("t.txt", "r", stdin);
int t;
scanf("%d", &t);
while (t--)
{
input();
sort(g, g + n);
work();
}
return 0;
}