British astronomer Eddington liked to ride a bike. It is said that in order to show off his skill, 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. Eddington‘s own E was 87.
Now given everyday‘s distances that one rides for N days, you are supposed to find the corresponding E (≤).
Each input file contains one test case. For each case, the first line gives a positive integer N (≤), the days of continuous riding. Then N non-negative integers are given in the next line, being the riding distances of everyday.
For each case, print in a line the Eddington number for these N days.
10 6 7 6 9 3 10 8 2 7 8
6
1 /* 2 Data: 2019-07-19 18:27:10 3 Problem: PAT_A1117#Eddington Number 4 AC: 13:54 5 6 题目大意: 7 E数定义:E天之中,骑行米数超过E的最大天数 8 9 基本思路: 10 从大到小排序,找到最大的i,使A[i]>i 11 */ 12 13 #include<cstdio> 14 #include<functional> 15 #include<algorithm> 16 using namespace std; 17 const int M=1e5+10; 18 int e[M]; 19 20 int main() 21 { 22 #ifdef ONLINE_JUDGE 23 #else 24 freopen("Test.txt", "r", stdin); 25 #endif 26 27 int n,pos; 28 scanf("%d", &n); 29 for(int i=1; i<=n; i++) 30 scanf("%d", &e[i]); 31 sort(e+1,e+n+1,greater<int>()); 32 for(pos=1; pos<=n; pos++) 33 if(e[pos] <= pos) 34 break; 35 if(pos==n && e[n]>n) 36 printf("%d", pos); 37 else 38 printf("%d", pos-1); 39 40 return 0; 41 }
原文:https://www.cnblogs.com/blue-lin/p/11215169.html