A1117 Eddington Number (25 point(s))

简单推理

1. 原文

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

Input Specification:

Each input file contains one test case. For each case, the first line gives a positive integer N (≤$10^5$), 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:

1
2
10
6 7 6 9 3 10 8 2 7 8

Sample output:

1
6

2. 解析

从大到小排序,记录个数,到值<个数时,找到该值

3. AC代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include<cstdio>
#include<algorithm>
using namespace std;
int num[100010]={};
bool cmp(int x,int y){
return x>y;
}
int main()
{
int n;
scanf("%d",&n);
for (int i = 0; i < n; ++i)
{
scanf("%d",&num[i]);
}
sort(num,num+n,cmp);
int ans=1;
for (int i = 0; i < n; ++i)
{
if (num[i]>ans)
{
ans++;
}
}
printf("%d\n",ans-1);
return 0;
}
本文结束  感谢您的阅读
  • 本文作者: Wang Ting
  • 本文链接: /zh-CN/2019/09/03/A1117/
  • 发布时间: 2019-09-03 12:29
  • 更新时间: 2021-10-29 14:08
  • 版权声明: 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!