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;
}
posted @ 2011-09-15 20:52  金海峰  阅读(202)  评论(0编辑  收藏  举报