A - Easy h-index(阅读理解)

The h-index of an author is the largest h where he has at least h papers with citations not less than h.
h-index 指数类似于打游戏时的称号等级,只是这里的这个等级的评判有两个方面:1.发布的论文数量h1。

2.这h1份论文的的总引用次数h2。要求h2 >= h1。
Bobo has published many papers.
Given a0,a1,a2,…,an which means Bobo has published ai papers with citations exactly i, find the h

-index of Bobo.
a0 -->  ai  --> an 代表ai份论文的引用次数分别为0-->i-->n。

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 n

.
The second line contains (n+1) integers a0,a1,…,an

.

Output

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

## Constraint

* 1≤n≤2⋅105

 

* 0≤ai≤109
* The sum of n does not exceed 250,000

.

Sample Input

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

Sample Output

1
2
0

题解:这道题就是从后往前累加,如果大于了i,则输出i。

例如:

   2

   1   2   3

i: 0   1   2

令sum = 0,从后往前累加:

1.sum += a[2]  --------------a[2]=3  ,  i=2

sum = 3,i = 2;

sum > i;

输出  i

(至于为什么输出的是i,其实可以这么想:评判的标准不是有两项吗,我们完全可以用“引用数量”来求h值)

这个样例的解释是,有h1 = 2份论文,它们的引用次数大于等于h2 = 2(这里要求h1 <= h2)

 

贴代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;

int a[1000005];
int main()
{
    int n;
    while(cin>>n){
        for(int i = 0;i < n+1;i++){
            cin>>a[i];
        }
        int sum = 0;
        bool flag = true;
        for(int i = n;i >= 0;i--){
            sum += a[i];
            if(sum >= i) {
                flag = false;
                cout<<i<<endl;
                break;
            }
        }
        if(flag){
            cout<<0<<endl;
        }
    }
    return 0;
}
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值