题意:优先级模拟
思路:循环队列处理。
#include<iostream>
using namespace std;
class queue
{
public:
int a;
bool pos;
queue()
{
pos=false;
}
};
void solve()
{
int n,pt,i,max;
cin>>n>>pt;
queue q[150];
q[pt].pos =true;
for(i=0;i<n;i++)
cin>>q[i].a ;
bool find=false;
int sta=0,star=0;
while(!find)
{
max=q[star].a ;bool change=false;
for(i=1;i<n;i++)
{
int j=(star+i)%150;
if(max<q[j].a )
{
change=true;
break;
}
}
if(change)
{
q[(star+n)%150]=q[star];
q[star].pos =false;
star=(star+1)%150;
}
else
{
if(q[star].pos)
{
cout<<sta+1<<endl;
find=true;
}
else {
sta++;
star=(star+1)%150;
n--;
}
}
}
}
int main()
{
int t;
cin>>t;
while(t--)
{
solve();
}
return 0;
}