-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1060.cpp
More file actions
50 lines (44 loc) · 849 Bytes
/
1060.cpp
File metadata and controls
50 lines (44 loc) · 849 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
bool cmp(int a, int b)//从大到小的排序
{
return a > b;
}
int main()
{
int n,max=0,flag=0;
vector<int> tem;//存放每天骑行的公里数
cin >> n;
for (int i = 0; i < n; i++)
{
int a;
scanf("%d",&a);
tem.push_back(a);
//max是骑行公里数的最大值与天数两者的更小者,爱丁顿数必然小于等于max
if (a > max)
max = a;
}
max = (max > n) ? n : max;
//公里数从大到小的排序
sort(tem.begin(),tem.end(),cmp);
//注意爱丁顿数不一定是某一个骑行公里数
for (; max>0; max--)
{
for (int i = 0; i < n; i++)
{
if (tem[i] > max&&tem[i + 1] <= max)
{
//i+1是骑行公里数大于max的天数,注意天数大于等于max即可,不需要等于max
if (i + 1 >= max)
flag = 1;
break;
}
}
if (flag)//已经找到艾丁顿数
break;
}
cout << max << endl;
return 0;
}