ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Kiki & Little Kiki 1 / HDU - 2275

2020-03-15 10:51:41  阅读:272  来源: 互联网

标签:2275 Little Pop st Kiki pop integer Push kiki


Kiki is considered as a smart girl in HDU, many boys fall in love with her! Now, kiki will finish her education, and leave school, what a pity! One day, zjt meets a girl, who is like kiki very much, in the campus, and calls her little kiki. Now, little kiki want to design a container, which has two kinds of operation, push operation, and pop operation.
Push M:
Push the integer M into the container.
Pop M:
Find the maximal integer, which is not bigger than M, in the container. And pop it from the container. Specially, for all pop operations, M[i] is no bigger than M[i+1].
Although she is as smart as kiki, she still can't solve this problem! zjt is so busy, he let you to help little kiki to solve the problem. Can you solve the problem?

Input

The input contains one or more data sets. At first line of each input data set is an integer N (1<= N <= 100000) indicate the number of operations. Then N lines follows, each line contains a word (“Push” or “Pop”) and an integer M. The word “Push” means a push operation, while “Pop” means a pop operation. You may assume all the numbers in the input file will be in the range of 32-bit integer.

Outout

For each pop operation, you should print the integer satisfy the condition. If there is no integer to pop, please print “No Element!”. Please print a blank line after each data set.

Sample Input

9
Push 10
Push 20
Pop 2
Pop 10
Push 5
Push 2
Pop 10
Pop 11
Pop 19
3
Push 2
Push 5
Pop 2

Sample Output

No Element!
10
5
2
No Element!

2

题意

多组测试数据,每组数据输入一个N

然后是N个操作

操作分两种

1: push x 表示插入x (多重集合)

2: pop x 表示删除<=x最大的一个整数并删除,不存在的话输出No Element!

题解

multiset 有序序列
upper_bound(key_value),返回最后一个大于等于x的定位器

代码

#include<bits/stdc++.h>
using namespace std;

int n, x;
string s;

int main(){
    while(scanf("%d", &n) == 1){
        multiset<int> st;
        while(n--){
            cin >> s; scanf("%d", &x);
            if(s == "Push"){
                st.insert(x);
            }else{
                multiset<int> :: iterator st_ = st.upper_bound(x);
                if(st_ != st.begin()){
                    st_--;
                    printf("%d\n", *st_);
                    st.erase(st_);
                }else{
                    printf("No Element!\n");
                }
            }
        }
        printf("\n");
    }
    return 0;
}

标签:2275,Little,Pop,st,Kiki,pop,integer,Push,kiki
来源: https://www.cnblogs.com/Little-Turtle--QJY/p/12496388.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有