hdu 2275数据结构水题

用multiset就可以水过,不过我这种方法用int会WA,应该是测试数据中有int的最小值,如果用int保存再取负的话就会溢出,以后要注意~~

/*
 * hdu2275/win.cpp
 * Created on: 2012-11-2
 * Author    : ben
 */
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <functional>
#include <numeric>
#include <cctype>
using namespace std;
typedef long long LL;

int main() {
#ifndef ONLINE_JUDGE
    freopen("data.in", "r", stdin);
#endif
    int N, a;
    LL temp;
    char str[100];
    while(scanf("%d", &N) == 1) {
        multiset<LL> S;
        while(N--) {
            scanf("%s %d", str, &a);
            temp = a;
            if(strcmp(str, "Push") == 0) {
                S.insert(-temp);
            }else {
                multiset<LL>::iterator it = S.lower_bound(-temp);
                if(it != S.end()) {
                    temp = -(*it);
                    printf("%d\n", (int)temp);
                    S.erase(it);
                }else {
                    puts("No Element!");
                }
            }
        }
        putchar('\n');
    }
    return 0;
}
原文地址:https://www.cnblogs.com/moonbay/p/2751829.html