A1117 Eddington Number (25分)

一、技术总结

  1. 题目读懂是关键,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.
  2. 定义一个E,对E天中超过E公里的最大数字就为E
  3. 定义一个数组存储每天的公里数,然后将他们从大到小排序,然后初始化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;
}
posted @ 2020-05-30 23:16  睿晞  阅读(121)  评论(0编辑  收藏  举报