CF888A.Local Extrema
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an array a. Some element of this array a__i is a local minimum iff it is strictly less than both of its neighbours (that is, a__i < a__i - 1 and a__i < a__i + 1). Also the element can be called local maximum iff it is strictly greater than its neighbours (that is, a__i > a__i - 1 and a__i > a__i + 1). Since _a_1 and a__n have only one neighbour each, they are neither local minima nor local maxima.
An element is called a local extremum iff it is either local maximum or local minimum. Your task is to calculate the number of local extrema in the given array.
给你一个数组 a。当数组中的某个元素 ai 严格小于其左右两个相邻元素时(即 ai<ai−1 且 ai<ai+1),称其为局部最小值。类似地,当某个元素 ai 严格大于其左右两个相邻元素时(即 ai>ai−1 且 ai>ai+1),称其为局部最大值。由于首尾元素 a1 和 an 各只有一个邻接元素,因此它们既不是局部最小值,也不是局部最大值。
若一个元素是局部最大值或局部最小值,则称其为局部极值。你的任务是计算给定数组中局部极值的个数。
输入格式
The first line contains one integer n (1 ≤ n ≤ 1000) — the number of elements in array a.
The second line contains n integers _a_1, _a_2, ..., a__n (1 ≤ a__i ≤ 1000) — the elements of array a.
第一行包含一个整数 n(1≤n≤1000)—— 数组 a 的元素个数。
第二行包含 n 个整数 a1,a2,…,an(1≤ai≤1000)—— 数组 a 的元素。
输出格式
Print the number of local extrema in the given array.
输出给定数组中局部极值的个数。
输入输出样例
输入#1
3 1 2 3
输出#1
0
输入#2
4 1 5 2 5
输出#2
2
输入解题思路,AI测评打分。不知道怎么写?