• 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 ;
    }
  • 相关阅读:
    java面试准备之基础排序——冒泡与选择排序
    PL/SQL 存储过程
    浅析Java中CountDownLatch用法
    tmux分屏幕
    two's complement
    angularJs中$controller的使用
    nodejs pipe实现大文件拷贝
    不错的网站
    echarts文档对照
    nodejs 项目的session验证
  • 原文地址:https://www.cnblogs.com/xiaolongchase/p/2205360.html
Copyright © 2020-2023  润新知