当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

7197:Multiply 2 Divide 2

题目描述
$\textbf{Note:There is no dependency between this problem and problem Hack of Multiply 2 Divide 2.}$

Frank_DD has a sequence $a$ of length $n$.

For each operation, he selects a number $a_i(1 \le i \le n)$ and changes it to $a_i\cdot 2$ or $\lfloor \frac{a_i}{2} \rfloor$.

Frank_DD wants to know the minimum number of operations to change the sequence $a$ to a non-descending sequence.
输入解释
The first line of the input contains one integer $T$ $($$1\leq T\leq 5$ $)$ --- the number of test cases. Then $T$ test cases follow.

In each test case:

The first line contains a single integer $n(1 \leq n \leq 10^5)$ --- the length of sequence $a$.

The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \leq a_i \leq 10^5)$ --- the sequence $a$.
输出解释
For each test case, print a single integer in a single line --- the minimum number of operations to change the sequence $a$ to a non-descending sequence.
输入样例
2
7
6 3 3 4 10 8 2
10
9 9 4 7 3 10 10 8 4 3
输出样例
4
11
来自杭电HDUOJ的附加信息
Hint In the first test case, we can use at least 4 operations to change the sequence $a$ to a non-descending sequence:$a_1=\lfloor \frac{a_1}{2} \rfloor$$a_5=\lfloor \frac{a_5}{2} \rfloor$$a_7=a_7 \cdot 2$$a_7=a_7 \cdot 2$

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-7197

最后修改于 2022-09-15T06:17:17+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
15000/7500MS(Java/Others) 524288/524288K(Java/Others)