哎哟……又要难死了……这个人啊……真的不行啊……
题目等暂时略掉。
求满足有 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;
}
很简单的累加,哎哟难死了,这个人怎么回事拉