JPMorgan ChaseOA #24
Get Minimum Operations
估计中等可在线判题
One operation picks an element and changes it to floor(v/2); it may become 0. Find the minimum number of operations so that every pair of adjacent elements ends up with different parity; a pairwise greedy that only changes the right element does not work.
输入格式
The first line contains n, followed by n items; full original bounds 1≤n≤100000, 1≤items[i]≤2^30.
输出格式
Output a single integer answer.
样例 1
输入:
5
4 10 10 6 2
输出:
2
样例 2
输入:
5
6 5 9 7 3
输出:
3
样例 3
输入:
2
2 4
输出:
1
样例说明
The outputs of the three public examples are, in order: 2; 3; 1. These answers have been checked by independent enumeration or direct simulation.