没去试能不能AC,总是要搞好久,留着自己看看而已
#include <iostream>
#include <algorithm>
using namespace std;
const int maxd = 10003;
#define point pair<int,int>
point arr[maxd];
int printorder[maxd];
int main()
{
int times,n,target;
scanf("%d", ×);
while (times--)
{
scanf("%d%d", &n, &target);
for (int i = 0;i < n;i++)
{
int t;
scanf("%d", &t);
point p = point(i, t);
arr[i] = p;
printorder[i] = t;
}
sort(printorder, printorder + n);
int k = n - 1,head=-1,tail=n;
int out = 0;//输出的时间
while (1)
{
head++;
if (arr[head].second == printorder[k])
{
out++;
k--;
if (arr[head].first == target)break;
}
else
arr[tail++] = arr[head];
}
printf("%d
", out);
}
return 0;
}