#include <iostream>
#include <queue>
using namespace std;
//谢谢博友好程序 模拟
struct pa{
int pri;
int pos;
};
queue <struct pa> da;
int main()
{
int count=0;
cin>>count;
//cout<<count<<endl;
while(count!=0)
{
count--;
int n,m;
cin>>n>>m;
//cout<<n<<" "<<m<<endl;
while(da.empty()!=1)
{
da.pop();
}
for(int i=0;i<n;i++)
{
int t;
cin>>t;
//cout<<t<<endl;
struct pa tem;
tem.pri=t;
tem.pos=i;
da.push(tem);
}
/*
for(int i=0;i<da.size();i++)
{
struct pa tem=da.front();
cout<<tem.pri<<" "<<tem.pos<<endl;
da.pop();
da.push(tem);
}*/
int jg=0;
int flag=1;
int time=0;
while(flag)
{
int zd=-1;//最大的优先级
for(int i=0;i<da.size();i++)
{
struct pa tem=da.front();
if(tem.pri>zd)
{
zd=tem.pri;
}
da.pop();
da.push(tem);
}
while(da.size()!=0)
{
struct pa tem=da.front();
if(tem.pri==zd)
{
da.pop();
time++;
if(tem.pos==m)
{
flag=0;
}
break;
}
da.pop();
da.push(tem);
}
}
cout<<time<<endl;
}
return 0;
}
POJ 3125 Printer Queue 模拟 G++
于 2017-07-17 19:49:13 首次发布