1060 爱丁顿数 (25 分)(思维)

英国天文学家爱丁顿很喜欢骑车。据说他为了炫耀自己的骑车功力,还定义了一个“爱丁顿数” E ,即满足有 E 天骑车超过 E 英里的最大整数 E。据说爱丁顿自己的 E 等于87。

现给定某人 N 天的骑车距离,请你算出对应的爱丁顿数 E(≤N)。

输入格式:

输入第一行给出一个正整数 N (≤10​5​​),即连续骑车的天数;第二行给出 N 个非负整数,代表每天的骑车距离。

输出格式:

在一行中给出 N 天的爱丁顿数。

输入样例:

10
6 7 6 9 3 10 8 2 7 8

输出样例:

6

题解:先排序,排完然后从大往小找,看看有多少个值比下标大的,发现就开始+1,最后输出即是最大

代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>

using namespace std;



int main() {

	int n;
	int a[100005];
	cin>>n;
	for(int t=0; t<n; t++) {
		scanf("%d",&a[t]);
	}
	sort(a,a+n);
	int temp=0;
	for(int t=n-1; t>=0; t--) {
		if(a[t]>n-t)
			temp++;
	}
	cout<<temp<<endl;

	return 0;
}
原文地址:https://www.cnblogs.com/Staceyacm/p/10781892.html