| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
STL list 好用#include<iostream>
#include<list>
using namespace std;
struct node
{
int data;
int no;
};
list<node>L;
list<node>::iterator iter;
int main()
{
int n,i,location,ans,flag,t;
node a,temp;
cin>>t;
while(t--)
{
while(!L.empty())
L.pop_front();
cin>>n>>location;
for(i=0;i<n;i++)
{
cin>>a.data;
if(i==location)
a.no=1;
else
a.no=0;
L.push_back(a);
}
ans=0;
while(!L.empty())
{
flag=0;
temp=L.front();
for(iter=L.begin();iter!=L.end();++iter)
{
if(iter->data>(temp.data))
{ flag=1;
L.pop_front();
L.push_back(temp);
// cout<<"temp "<<temp.data<<" "<<temp.no<<endl;
break;
}
}
if(flag==0)
{
//cout<<L.front().data<<" "<<L.front().no<<endl;
if(L.front().no==1)
break;
L.pop_front();
ans++;
}
}
cout<<ans+1<<endl;
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator