<span style="font-family: Arial, Helvetica, sans-serif;">对队列不懂的 可以看看我转的这篇文章<a target=_blank href="http://blog.csdn.net/su20145104009/article/details/44562659" target="_blank">STL整理</a>。</span>
<pre name="code" class="cpp">#include <stdio.h> #include <queue> using namespace std; typedef struct { int rich,num; }node; queue<node> s1; priority_queue<int,vector<int>,less<int> >s2;//把less换成greater就是从小到大 int main() { node t,v; int n,m,x; while(scanf("%d %d",&n,&m)!=EOF) { while(!s1.empty())//必须清队列 s1.pop(); while(!s2.empty())//同上 s2.pop(); for(int i=0;i<n;i++) { scanf("%d",&x); t.rich=x; t.num=i; s1.push(t); s2.push(x); } for(int i=0;i<n;i++) { v=s1.front(); if(v.rich==s2.top()) s2.pop(); else { while(v.rich!=s2.top()) s1.push(v),s1.pop(),v=s1.front(); s2.pop(); } if(v.num==m) { s1.pop(); break; } else s1.pop(); } printf("%d\n",n-s2.size()); } return 0; }
时间: 2024-10-12 03:03:01