zoukankan      html  css  js  c++  java
  • hdu 2275 Kiki & Little Kiki 1 水题

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=2275

    这个题比较简单,所以就没有测试样例提供给大家,基本把题目的样例过了就可以了

    题目大意

    给你一串操作,“Push  x”为添加元素x ;    

    “Pop  x”为:在集合中找到一个不大于x的最大数,输出并删除,没有的话,输出“No Element!”

    最后留一个空行

    存储结构

    multiset,一种允许有重复元素的set

    思路

    用set自带的upper_bound()函数找到大于x的位置,输出其前一个位置的元素值,如果不存在,那么一定返回一个begin()(意为全大于),判断即可

    代码如下:

     1 #include<iostream>
     2 #include<set>
     3 #include<string>
     4 using namespace std;
     5 
     6 int main()
     7 {
     8     int Group, number;
     9     while (cin >> Group)
    10     {
    11         multiset<int> S;
    12         string s;
    13         while (Group--)
    14         {
    15             cin >> s >> number;
    16             if (s == "Push")
    17                 S.insert(number);
    18             else {
    19                 multiset<int>::iterator it = S.upper_bound(number);
    20                 if (it == S.begin())
    21                     cout << "No Element!" << endl;
    22                 else {
    23                     cout << *(--it) << endl;
    24                     S.erase(it);
    25                 }
    26             }
    27         }
    28         cout << endl;
    29     }
    30 }

    谢谢您的阅读,生活愉快~

  • 相关阅读:
    terminator shortcut
    支付宝集成错误
    null与DBNULL
    linode接连出问题,我也没看懂英文
    ruby 日期 好函数
    ruby datetime
    act as tree插件
    ruby 时间
    ruby规则引擎
    on ,type等关键词,使用
  • 原文地址:https://www.cnblogs.com/lv-anchoret/p/8371700.html
Copyright © 2011-2022 走看看