#P8787. [蓝桥杯 2022 省 B] 砍竹子
[蓝桥杯 2022 省 B] 砍竹子
Problem Description
On this day, Xiaoming is cutting bamboo. In front of him there are bamboo plants in a row. At the beginning, the height of the -th bamboo plant is .
He feels that cutting them one by one is too slow, so he decides to use magic to cut the bamboo. The magic can be used on a consecutive segment of bamboo plants that all have the same height. Suppose the height of this segment is . Then using the magic once can change the heights of all bamboo plants in this segment to $\left\lfloor\sqrt{\left\lfloor\frac{H}{2}\right\rfloor+1}\right\rfloor$, where means rounding down.
Xiaoming wants to know the minimum number of times he needs to use magic to make the heights of all bamboo plants become .
Input Format
The first line contains a positive integer , representing the number of bamboo plants.
The second line contains positive integers separated by spaces, representing the height of each bamboo plant.
Output Format
Output one integer, the answer.
6
2 1 4 2 6 7
5
Hint
Sample Explanation.
One possible plan:
$214267\rightarrow 214262\rightarrow 214222\rightarrow 211222\rightarrow 111222\rightarrow 111111$
A total of 5 steps are needed.
Constraints.
For of the testdata, it is guaranteed that and .
For of the testdata, it is guaranteed that and .
Lanqiao Cup 2022 Provincial Contest B Group, Problem J.
Translated by ChatGPT 5