一、技术总结
- 题目读懂是关键,he has even defined an "Eddington number", E -- that is, the maximum integer E such that it is for E days that one rides more than E miles.
- 定义一个E,对E天中超过E公里的最大数字就为E
- 定义一个数组存储每天的公里数,然后将他们从大到小排序,然后初始化e=0,如果数组中a[e] > e+1,就e++,直到不符合条件。
二、参考代码
#include<bits/stdc++.h>
using namespace std;
int a[100010];
int main(){
int n, e = 0;
scanf("%d", &n);
for(int i = 0; i < n; i++){
scanf("%d", &a[i]);
}
sort(a, a+n, greater<int>());
while(e < n && a[e] > e+1) e++;
printf("%d", e);
return 0;
}