12100-Printer Queue【STL模拟】

纯队列模拟。

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<set>
using namespace std;
struct Paper{
    int Lv;
    int is_my;
};
#define MAXD 100 + 10
int main(){
    int T;
    scanf("%d",&T);
    while(T--){
        int n,m;
        queue<Paper>q;
        int array[MAXD];
        scanf("%d%d",&n,&m);
        int top = n - 1;
        for(int i = 0 ; i < n ; i++){
          scanf("%d",&array[i]);
          Paper temp;
          temp.Lv = array[i];
          if(i == m) temp.is_my = 1;
          else       temp.is_my = 0;
          q.push(temp);
        }
        sort(array,array + n);
        int _count = 0;
        while(true){
            Paper temp;
            temp = q.front();
            q.pop();
            if(temp.Lv == array[top]){
                _count ++ ;
                top --;
                if(temp.is_my == 1) break;
            }
            else {
                q.push(temp);
            }
        }
        printf("%d\n",_count);
    }
    return 0;
}


你可能感兴趣的:(12100-Printer Queue【STL模拟】)