大连的网络赛悲剧了,没有出线,看来还得继续努力呀!!奋斗!
在此曝上1006的解题报告,我用优先队列做的,看来STL是超有用呀,提醒做ACM的要掌握好STL呀^_^~~~~
#include <algorithm> #include <iostream> #include <string.h> #include <stdio.h> #include <math.h> #include <map> #include <vector> #include <queue> #include <stack> using namespace std; int main() { int n,k; while(scanf("%d%d",&n,&k)!=EOF){ priority_queue< int ,vector < int >,greater<int> > q; int i; for(i=0;i<n;i++){ char c; getchar(); c = getchar(); if(c=='I') { int g; scanf("%d",&g); if(q.empty()) { q.push(g); } else { if(q.size()<k)q.push(g); else {//维持队列的大小始终为k int kk=q.top(); if(g>=kk)//比当前的第k大数大的数留下,其他的丢掉 { q.pop(); q.push(g); } } } } else if(c=='Q') { int r=q.top();//输出队列中的最小值,即为答案 printf("%d\n",r); } } } return 0; }