PTA Basic 1060 爱丁顿数

英国天文学家爱丁顿很喜欢骑车。据说他为了炫耀自己的骑车功力,还定义了一个“爱丁顿数” 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

 将输入从小到大排序,然后遍历,如果小于index+1(天数从1开始),那么index就是最大的满足天数。需要注意下边界的处理,可能所有天数都满足要求。

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <cmath>
#include <vector>
#include <map>
#include <cstring>
#include <time.h>
#include <iostream>
#include <algorithm>

using namespace std;

int cmp(int a, int b) {
	return a > b;
}

int main() {

	int n;
	cin >> n;
	int days[n];

	for (int i = 0; i < n; i++) {
		cin >> days[i];
	}
	sort(days, days+n, cmp);

	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (days[i] > i+1){
			if (n == i+1)
				ans = n;
			else
				continue;
		}
		else {
			ans = i;
			break;
		}
	}
	cout << ans;

	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值