标签:
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2275
题意:n个操作
Push 入容器
Pop弹出一个 满足<=该数的最大的数(若没有输出No Element!)
用两个堆模拟。
1 #include<functional> 2 #include<algorithm> 3 #include<iostream> 4 #include<string> 5 #include<cstdlib> 6 #include<cstring> 7 #include<cstdio> 8 #include<vector> 9 #include<queue> 10 using std::vector; 11 using std::greater; 12 using std::priority_queue; 13 priority_queue<int> que1; 14 priority_queue<int, vector<int>, greater<int> >que2; 15 void solve(){ 16 int v; 17 char buf[10]; 18 scanf("%s %d", buf, &v); 19 if (‘u‘ == buf[1]){ 20 que2.push(v); 21 } else { 22 while(!que2.empty()){ 23 int x = que2.top(); 24 if (x <= v) que1.push(x), que2.pop(); 25 else break; 26 } 27 if (que1.empty()) puts("No Element!"); 28 else printf("%d\n", que1.top()), que1.pop(); 29 } 30 } 31 int main(){ 32 #ifdef LOCAL 33 freopen("in.txt", "r", stdin); 34 freopen("out.txt", "w+", stdout); 35 #endif 36 int n; 37 while (~scanf("%d", &n)){ 38 while (n--) solve(); 39 while (!que1.empty()) que1.pop(); 40 while (!que2.empty()) que2.pop(); 41 printf("\n"); 42 } 43 return 0; 44 }
标签:
原文地址:http://www.cnblogs.com/GadyPu/p/4483123.html