zoukankan      html  css  js  c++  java
  • hdu 1873

        题目链接: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 ;
    }
  • 相关阅读:
    谷粒商城学习——P52商品服务-API-三级分类-新增效果
    验证码爆破总结
    利用crawlergo-to-xray实现自动化漏洞被动扫描平台搭建
    数据导入经验总结
    SQL实现2个日期之间的工作日数(MySQL)(转)
    MySQL查询所有表的数据量
    crontab定时配置(转)
    SQLyog还原会话失败
    Nginx以xxx开头的转发
    mysql备份shell脚本
  • 原文地址:https://www.cnblogs.com/xiaolongchase/p/2205360.html
Copyright © 2011-2022 走看看