toj 2196 Nuanran's Idol II multiset应用
题目地址:toj2196
题目意思:每次维护一个可重集合中的最小元素
用优先权队列或者multiset
代码:
#include<iostream> #include<queue> #include<cstdio> #include<set> using namespace std; struct cmp { bool operator() (const int a,const int b) const { return a>b; } }; int main() { int n; while(cin>>n) { if(n==0) break; // char ch; // multiset<int> s; // multiset<int> ::iterator it; // int value; // for(int i=0;i<n;i++) // { // cin>>ch; // if(ch=='B') // {cin>>value; // s.insert(value); // // } // // else // { // it=s.begin(); // cout<<*it<<endl; // s.erase(it); // // } // } // // } char ch; int value; priority_queue<int,vector<int>,cmp> pq; for(int i=0;i<n;i++) { cin>>ch; if(ch=='B') { scanf("%d",&value); pq.push(value); } else if(ch=='G') { value=pq.top(); cout<<value<<endl; pq.pop(); } } } }
posted on 2014-03-19 19:25 814jingqi的ACM 阅读(186) 评论(0) 编辑 收藏 举报