Easy h-index

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

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

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.

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

题目大意:
a[i]为发表篇数,i为引文篇数。
找出一个h,满足:至少有h篇且引文不低于h的论文

因为已知篇数,不低于,有这个关键词我们想到把循环倒着过来找。因为i是逐渐增大的,所以引文篇数也逐渐增大。

本题考点是一个简单的前缀和(是今天尝试在学的一个新东西orz)。

通过的代码如下:

#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
int a[200010];
int main(){
int n;
while(scanf("%d",&n)!=EOF)
{
	int sum=0;
	for(int i=0;i<=n;i++)
	{
		scanf("%d",&a[i]);
	 }
	 for(int i=n;i>=0;i--)
	 {
	 	sum+=a[i];     //倒着加起来
	 	if(sum>=i)     //这个i就是要找的h
	 	{
	 		printf("%d\n",i);
	 		break;
		 }
	  }
	 
}
	return 0;
}
发布了8 篇原创文章 · 获赞 0 · 访问量 169

猜你喜欢

转载自blog.csdn.net/Erin_jwx/article/details/103950090
今日推荐