AcWing 1768. H 指数
原题链接
简单
作者:
JAVA小老弟
,
2020-06-20 16:29:12
,
所有人可见
,
阅读 557
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
public class Main{
public static void main(String[] args) throws IOException {
BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
String line[] = r.readLine().split(" ");
int n = Integer.valueOf(line[0]);
String line2[] = r.readLine().split(" ");
int[] arr = new int[n];
for (int i = 0; i <n ; i++) {
arr[i] = Integer.valueOf(line2[i]);
}
Arrays.sort(arr);//先对数组进行排序
int left = 0;
int right = arr[arr.length-1];
int res = 0;
while(left<right){
int mid = (left+right)/2+1;//找到中间数
int cnt = 0;
for (int i = 0; i <arr.length ; i++) {
if(arr[i]>=mid)//看看有几个论文超过了他
cnt++;
}
if(cnt>=mid){//如果H指数超过的之前的话 置新的
res = mid; //7个5 还是置5
left = mid;
}
else{
right = mid-1;
}
}
System.out.println(res);
}
}