PAT 1060 爱丁顿数(累加思想)

哎哟……又要难死了……这个人啊……真的不行啊……

题目等暂时略掉。

求满足有 E 天骑车超过 E 英里的最大整数 E。

10
6 7 6 9 3 10 8 2 7 8

已案例为例,排好序,因为最大的数一定会比第E天大,所以干脆排个序。

E天             E

1                 10           1天超过了1公里(指E=10)  E=1

2                  9            2天超过了2公里(指E=10 && E=9) E=2

3                  8            3天超过了3公里(指前三个 下略)E=3

4                  8            4天超过了4公里

5                  7           5天超过了5公里

6                  7           6天超过了6公里

7                  6           7天但是超过7的数只有4个 所以到这里就停止了 可以退出了。

8                  6

9                  3

10                2

#include <iostream>
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

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

int main()
{
	int n;
	cin >> n;
	int a[100005] = { 0 };
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
	}
	sort(a + 1, a + 1 + n, cmp);
	int maxx = 0;
	for (int i = 1; i <= n; i++)//第E天 查看第E天是否大于E 若大于则E成立
	{
		if (a[i] <= i)
			break;
		maxx++;
	}
	cout << maxx << endl;
	system("pause");
	return 0;
}

很简单的累加,哎哟难死了,这个人怎么回事拉

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值