poj3125 Printer Queue

来源:互联网 发布:手机淘宝怎么提交改价 编辑:程序博客网 时间:2024/04/27 12:07

模拟

#include <iostream>#include <stdio.h>#include <string.h>using namespace std;#define N 10004typedef struct node{   int pos,pri;};node q[N];int pri[10];int main(){    int n,t,m,maxx,f,r,po,ans;    cin>>t;    node tmp;    while(t--){        cin>>n>>m;        memset(pri,0,sizeof(pri));        maxx=-1;        ans=0;        f=0;        r=n;        for(int i=0;i<n;i++){            scanf("%d",&q[i].pri);            q[i].pos=i;            pri[q[i].pri]++;            maxx=max(maxx,q[i].pri);        }        po=maxx;        while(1){            tmp=q[f++];            if(tmp.pri<po){                q[r++]=tmp;                continue;            }            else{                if(tmp.pos==m){                    ans++;                    break;                }                else{                    ans++;                    pri[po]--;                    while(!pri[po]&&po>0){                        po--;                    }                }            }        }        printf("%d\n",ans);    }    return 0;}


0 0
原创粉丝点击