其他分享
首页 > 其他分享> > 1060 爱丁顿数 (25 分)

1060 爱丁顿数 (25 分)

作者:互联网

英国天文学家爱丁顿很喜欢骑车。据说他为了炫耀自己的骑车功力,还定义了一个“爱丁顿数” E ,即满足有 E 天骑车超过 E 英里的最大整数 E。据说爱丁顿自己的 E 等于87。

现给定某人 N 天的骑车距离,请你算出对应的爱丁顿数 E(≤N)。

输入格式:

输入第一行给出一个正整数 N (≤105),即连续骑车的天数;第二行给出 N 个非负整数,代表每天的骑车距离。

输出格式:

在一行中给出 N 天的爱丁顿数。

输入样例:

10
6 7 6 9 3 10 8 2 7 8

输出样例:

6
#include<iostream>
using namespace std;
int main(){
	int n,x,a[1000000]={0},max=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>x;
		if(x>max)max=x;
		if(x>0)a[x-1]++;
	}
    if(max==0)cout<<0;
	for(int i=max-1;i>=0;i--){
		a[i]=a[i]+a[i+1];
		if(i<=a[i]){
			cout<<i;
			break;
		}
	}
    return 0;
}

 

标签:25,max,10,int,1060,爱丁顿,样例,骑车
来源: https://blog.csdn.net/BAFH499/article/details/122758312