您的位置:首页 > 理论基础 > 数据结构算法

hdu 2275数据结构水题

2012-11-02 20:26 260 查看
用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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: