hdu 2275 Kiki & Little Kiki 1

原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2275
题意:n个操作
Push 入容器
Pop弹出一个 满足<=该数的最大的数(若没有输出No Element!)
用两个堆模拟。

#include<functional>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
using std::vector;
using std::greater;
using std::priority_queue;
priority_queue<int> que1;
priority_queue<int, vector<int>, greater<int> >que2;
void solve(){
    int v;
    char buf[10];
    scanf("%s %d", buf, &v);
    if ('u' == buf[1]){
        que2.push(v);
    } else {
        while(!que2.empty()){
            int x = que2.top();
            if (x <= v) que1.push(x), que2.pop();
            else break;
        }
        if (que1.empty()) puts("No Element!");
        else printf("%d\n", que1.top()), que1.pop();
    }
}
int main(){
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w+", stdout);
#endif
    int n;
    while (~scanf("%d", &n)){
        while (n--) solve();
        while (!que1.empty()) que1.pop();
        while (!que2.empty()) que2.pop();
        printf("\n");
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值