加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

PAT_A1117#Eddington Number

发布时间:2020-12-14 04:40:52 所属栏目:大数据 来源:网络整理
导读:Source: PAT A1117?Eddington Number?(25?分) Description: 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

Source:

PAT A1117?Eddington Number?(25?分)

Description:

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?(≤).

Input Specification:

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.

Output Specification:

For each case,print in a line the Eddington number for these?N?days.

Sample Input:

10
6 7 6 9 3 10 8 2 7 8

Sample Output:

6

Keys:

  • 模拟题

Code:

 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 }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读