zoukankan      html  css  js  c++  java
  • hdu2275 Kiki & Little Kiki 1 (多重集合的应用)

    multiset 第一次用,太神奇了

    题意:push a 把a压栈;pop b 把小于等于b的所有元素中最大的元素的出栈,若没有则输出“No Element!”!

    View Code
    #include<iostream>  
    #include<stdio.h>  
    #include<set>  
    using namespace std;  
    int main()  
    {  
        multiset<int> st;  
        multiset<int>::iterator it;  
        int n;  
        char op[5];  
        int tp;  
        while(scanf("%d",&n)!=EOF)  
        {  
            st.clear();  
            while(n--)  
            {  
                scanf("%s%d",op,&tp);  
                if(op[1]=='u')  
                    st.insert(tp); 
                else 
                {  
                    it=st.upper_bound(tp);//返回容器元素中大于tp的迭代器  
                    if(it==st.begin()) //等于begin() 表示不存在小于等于tp的元素
                        printf("No Element!\n");  
                    else
                    {  
                        it--;  
                        if(*it<=tp)  
                        {  
                            printf("%d\n",*it);  
                            st.erase(it);  
                        }  
                        else 
                            printf("No Element!\n");  
                    }  
                }  
            } 
            printf("\n");  
        }  
    }
  • 相关阅读:
    C#垃圾回收(GC)
    yum --enablerepo=elrepo-kernel install kernel-lt -y
    centos 查看版本
    linux 内核升级
    awk
    升级内核
    elerpo
    http://elrepo.org/tiki/tiki-index.php
    NO_TITLE
    MongoDB Find查询 1
  • 原文地址:https://www.cnblogs.com/nanke/p/2518697.html
Copyright © 2011-2022 走看看