原题条件:
- h指数等于使得研究员有至少 h h h篇引用次数不少于h的论文的最大整数h
- 综述对于文献的引用最多引用一次,且 L < = N L<=N L<=N
思考:
根据“至少有h篇”,可得出h一定不会超过总篇数N,故在得出h的数值时,循环只需循环到N即可。
对于 :
4 1
1 100 3 3
这样的带有重复的数值,综述引用第三或者第四个 3 3 3,对于最终结果来说并没有影响,故利用桶结构对研究文献数组 c c c进行统计
AC代码:
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int tong[100010];
int N,L;
int temp=0; //临时变量
int main()
{
cin>>N>>L;
for(int i=1;i<=N;i++)
{
cin>>temp;
tong[temp]++;
}
int ans=0;
temp=N;
for(ans=0;ans<N;ans++) //由于h指数的定义,h指数不会大于论文总数
{
temp-=tong[ans]; //temp表示:引用量 > ans 的文章的篇数
if(temp+min(tong[ans],L)<=ans) break;
//temp + min(cnt[ans], L) 表示:引用量包括ans的或是加上L个引用之后引用量> ans的文章的篇数
}
cout<<ans<<endl;
return 0;
}
注:
t
e
m
p
−
=
t
o
n
g
[
a
n
s
]
temp -= tong[ans]
temp−=tong[ans],
t
e
m
p
temp
temp表示的就是 >
a
n
s
ans
ans 的 的个数,而它能改变的就是当前的
a
n
s
ans
ans,使他成为
a
n
s
+
1
ans + 1
ans+1,最多是
m
i
n
(
t
o
n
g
[
a
n
s
]
,
l
)
min(tong[ans], l)
min(tong[ans],l)次,
t
e
m
p
+
m
i
n
(
t
o
n
g
[
a
n
s
]
,
l
)
temp + min(tong[ans], l)
temp+min(tong[ans],l) 就是>
a
n
s
ans
ans更改后的个数。