您的位置:首页 > 其它

1060. 爱丁顿数(25)

2018-03-05 17:59 281 查看
1060. 爱丁顿数(25)

时间限制 250 ms 内存限制 65536 kB 代码长度限制 8000 B

判题程序 Standard 作者 CHEN, Yue

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

思路,从大到小排序,离下标0最远的那个大于其下标加一的即为结果

#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <iostream>
#include <string>

using namespace std;
const int MaxN = 100010;

int main() {
#ifdef _DEBUG
freopen("data.txt", "r+", stdin);
#endif // _DEBUG
std::ios::sync_with_stdio(false);

int n,data[MaxN]; cin >> n;
for (int i = 0; i < n; ++i)cin >> data[i];
sort(data, data + n, [](int a, int b) {return a > b; });
int t = 1;
for (int i = 0; i < n; ++i) {
if (data[i] <= t)break;
++t;
}

cout << t-1;
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  pat乙级 1060