题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1873

    主要是排序,sort和qsort是不稳定排序,所以在此题种不可用。而stable_sort为稳定排序,每次IN后对vector排序即可。

 

 

#include<iostream>
#include<vector>
#include <algorithm>

using namespace std ;

struct pain{
    int tip, id ;
};
int cmp(pain a ,pain b){
    return a.tip > b.tip ;
}
int main(){
    int n ;
    typedef vector<pain> dlist ;
    dlist list[4] ;
    while(cin >> n){
        int k=0 ;
        int docnum ;
        for(int i=1; i<=3; i++)
            list[i].clear() ;
        for(int i=0; i<n; i++){
            string str ;
            cin >> str ;
            pain t ;
            if(str[0]=='I'){
                cin >> docnum >> t.tip ;
                t.id = k+1 ;
                list[docnum].push_back(t) ;
                stable_sort(list[docnum].begin(),list[docnum].end(),cmp) ;
                k ++ ;
            }
            else{
                cin >> docnum ;
                if(list[docnum].empty())
                    cout << "EMPTY" << endl ;
                else{
                    cout << list[docnum].begin()->id << endl ;
                    dlist::iterator it = list[docnum].begin() ;
                    list[docnum].erase(it) ;
                }
            }
        }
    }
    return 0 ;
}

 

 

posted on 2011-10-10 12:16  追逐.  阅读(256)  评论(0编辑  收藏  举报