在线评测:
http://codevs.cn/problem/3289/
整体思路:
首先这道题可以用DP模仿最长上升子序列得到80分,然后我们来考虑一下正解应该怎么写。题意可以简化为选择尽可能多的花组成一个波浪型,然后我们我考虑,在每一个波峰上,在不影响后续的情况下,选取尽可能大的情况最顶最优。在波谷上,在不影响后续的情况下,选取尽可能小的情况也一定最优秀。因为尽可能大/小,我们后续的选择余地就更大。所以我们可以进行贪心。
失误之处:
题意描述不允许直线的存在,而我则允许了最后所有高度成为一个直线,丢了20分。
体会心得:
认真读题,注意细节。
AC代码:
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
int n,ans1,ans2,hi,lo;
int sz[200000];
bool feng;
int main()
{
scanf(
"%d"
,&n);
for
(int i = 1;i <= n;i++)
scanf(
"%d"
,&sz[i]);
int i = 2;
ans1 = 1;
while
(i <= n)
{
if
(!feng)
{
if
(sz[i] <= sz[i-1])
{
}
else
{
ans1++;
feng =
true
;
}
}
else
{
if
(sz[i] >= sz[i-1])
{
}
else
{
ans1++;
feng =
false
;
}
}
i++;
}
feng =
true
;
i = 2;
ans2 = 1;
while
(i <= n)
{
if
(!feng)
{
if
(sz[i] <= sz[i-1])
{
}
else
{
ans2++;
feng =
true
;
}
}
else
{
if
(sz[i] >= sz[i-1])
{
}
else
{
ans2++;
feng =
false
;
}
}
i++;
}
printf(
"%d\n"
,max(ans1,ans2));
return
0;
}
|