
ZOJ Problem Set  4107
Baobao loves singing very much and he really enjoys a game called Singing Everywhere, which allows players to sing and scores the players according to their performance. Consider the song performed by Baobao as an integer sequence $a_1, a_2,\dots,a_n$, where $a_i$ indicates the $i$th note in the song. We say a note $a_k$ is a "voice crack" if $1 < k < n$, $a_{k1} < a_k$ and $a_{k+1} < a_k$. The more voice cracks BaoBao sings, the lower score he gets. To get a higher score, BaoBao decides to delete at most one note in the song. What's the minimum number of times BaoBao sings a voice crack after this operation? InputThere are multiple test cases. The first line of the input contains an integer $T$ (about 100), indicating the number of test cases. For each test case: The first line contains one integer $n$ ($1 \leq n \leq 10^{5}$), indicating the length of the song. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($2^{31} \leq a_i < 2^{31}$), indicating the song performed by BaoBao. It's guaranteed that at most 5 test cases have $n > 100$. OutputFor each test case output one line containing one integer, indicating the answer. Sample Input3 6 1 1 4 5 1 4 7 1 9 1 9 8 1 0 10 2 1 4 7 4 8 3 6 4 7 Sample Output1 0 2 HintFor the first sample test case, BaoBao does not need to delete a note. Because if he deletes no note, he will sing 1 voice crack (the 4th note), and no matter which note he deletes, he will also always sing 1 voice crack. For the second sample test case, BaoBao can delete the 3rd note, and no voice cracks will be performed. Yay! For the third sample test case, BaoBao can delete the 4th note, so that only 2 voice cracks will be performed (4 8 3 and 3 6 4). Author: CHEN, Jingbang Source: The 16th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple 