1060 爱丁顿数 (25 分)

本文介绍了一种有趣的数学概念——爱丁顿数,它是衡量骑车者成就的指标,即满足有E天骑车超过E英里的最大整数E。文章通过一个编程问题,探讨了如何计算给定骑车距离数据集的爱丁顿数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

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

输入格式:

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

输出格式:

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

输入样例:

10
6 7 6 9 3 10 8 2 7 8

输出样例:

6

分析:

 原先的代码:

// B60.cpp : Defines the entry point for the console application.
//

#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;

int main()
{
	int n;
	int ans = 0;
	cin >> n;
	int a[10004];
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	sort(a, a + n);
	for (int i = 0; i < n; i++)
	{
		if (a[i] > n - i)
		{
			ans = n - i;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

结果有一个断点无法通过。提示段错误。

最终没有找到错误的点。

从网上找到一份AC代码。

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int a[1000001];
bool cmp(int a,int b){
    return a>b;
}
int main(){
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    sort(a+1,a+n+1,cmp);
    int ans = 0;
    int p = 1;
    while(ans<=n&&a[p]>p){
        ans++;
        p++;
    }
    printf("%d",ans);
    return 0;
}
--------------------- 
作者:会很好笑诶 
来源:优快云 
原文:https://blog.youkuaiyun.com/hy971216/article/details/80691442 
版权声明:本文为博主原创文章,转载请附上博文链接!

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值