利用小根堆存当前最小值
最近选导师,正好做这题了解下H指数怎么算
顺便一提:据说优秀学者H指数至少要不小于入行年份
#include <iostream>
#include <queue>
using namespace std;
const int N=100010;
int n,m,a[N];
int main(){
scanf("%d",&n);
int j=1,h;
while(n--){
h=0;
priority_queue<int,vector<int>,greater<int>> heap;
scanf("%d",&m);
cout << "Case #" << (j++) << ": ";
for(int i=0;i<m;i++){
scanf("%d",a+i);
if(a[i]>h) heap.push(a[i]);
if(heap.size()>h&&heap.top()>h) h++;
while(heap.size()&&heap.top()<=h) heap.pop();
cout << h << " ";
}
cout << endl;
}
return 0;
}