HDU - 6276 Easy $h$-index

版权声明:转载时标明一下出处啦QwQ https://blog.csdn.net/Zero_979/article/details/81539872

比赛题目: 
http://acm.hdu.edu.cn/downloads/2018ccpc_hn.pdf 

The hh-index of an author is the largest hh where he has at least hh papers with citations not less than hh. 

Bobo has published many papers. 
Given a0,a1,a2,…,ana0,a1,a2,…,an which means Bobo has published aiai papers with citations exactly ii, find the hh-index of Bobo. 
 

Input

The input consists of several test cases and is terminated by end-of-file. 

The first line of each test case contains an integer nn. 
The second line contains (n+1)(n+1) integers a0,a1,…,ana0,a1,…,an. 

Output

For each test case, print an integer which denotes the result. 

## Constraint 

* 1≤n≤2⋅1051≤n≤2⋅105 
* 0≤ai≤1090≤ai≤109 
* The sum of nn does not exceed 250,000250,000. 

Sample Input

1
1 2
2
1 2 3
3
0 0 0 0

Sample Output

1
2
0

思路:

给你一组数,每个数的个数是它的下标i,要找一个h,使得h最大,有h个大于等于h的数字。

代码:

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
int a[250002];
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF){

        memset(a,0,sizeof(a));
        for(int i=0;i<=n;i++){
            scanf("%d",&a[i]);
        }
        int s=0;
        for(int i=n;i>=0;i--){
            s=s+a[i];
            if(s>=i){
                printf("%d\n",i);
                break;
            }
        }
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/Zero_979/article/details/81539872