uva 11491 - Erasing and Winning【优先队列模拟】

直接模拟吧。。。很暴力的解法

#include<cstdio>
#include<cstring>
#include<iostream>
#include<list>
#include<queue>
#include<algorithm>
#include<stack>
using namespace std;
#define MAXD 100000 + 10
struct Num{
    int id;
    int value;
    friend bool operator < (Num p,Num q){
        if(p.value > q.value)
          return  true;
        else
          return false;
    }
};
int cmp(Num p,Num q){
    if(p.id < q.id)
    return true;
    else
    return false;
}
int main(){
    int n,m;
    while(scanf("%d%d",&n,&m)){
        getchar();
        if(!n && !m) break;
        int size = 0;
        Num number[MAXD];
        priority_queue<Num>q;
        for(int i = 0 ; i < n ; i++){
            char c;
            Num t;
            scanf("%c",&c);
            t.id = i;
            t.value = c - '0';
            while(!q.empty() && m){
                int _min = q.top().value;
                if(_min < t.value){
                    q.pop();
                    m--;
                }
                else
                break;
            }
            q.push(t);
        }
        while(!q.empty()){
            number[size ++] = q.top();
            q.pop();
        }
        sort(number,number + size,cmp);
        for(int i = 0 ; i < size - m ; i++)
        printf("%d",number[i].value);
        printf("\n");
    }
    return 0;
}


你可能感兴趣的:(uva 11491 - Erasing and Winning【优先队列模拟】)