308259: CF1490A. Dense Array

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Dense Array

题意翻译

如果序列 $a$ 的任意相邻两项中,较大者不大于较小者的二倍,则 Polycarp 称 $a$ 是一个密集序列。形式化地,序列 $a$ 是密集的,等价于 $$\forall\ 1 \leqslant i < n, \frac{\max(a_i, a_{i + 1})}{\min(a_i, a_{i + 1})} \leqslant 2.$$ 例如:序列 $[1, 2, 3, 4, 3]$、$[1, 1, 1]$、$[5, 10]$ 是密集的;序列 $[5, 11]$、$[1, 4, 2]$、$[6, 6, 1]$ 不是密集的。 你有一个序列 $a$,你可以在其任意位置插入任意正整数,求最少需要插入多少个数才能使 $a$ 变为密集的。 例如:$a = [4, 2, 10, 1]$,则答案为 $5$,插入后的序列可以为 $a' = [4, 2, \underline 3, \underline 5, 10, \underline 6, \underline 4, \underline 2, 1]$。当然还有其他插入数的方式。 $1 \leqslant t \leqslant 1000$,$1 \leqslant n \leqslant 50$,$1 \leqslant a_i \leqslant 50$。 Translated by [KHIN](/user/236807).

题目描述

Polycarp calls an array dense if the greater of any two adjacent elements is not more than twice bigger than the smaller. More formally, for any $ i $ ( $ 1 \le i \le n-1 $ ), this condition must be satisfied: $ \frac{\max(a[i], a[i+1])}{\min(a[i], a[i+1])} \le 2 $ For example, the arrays $ [1, 2, 3, 4, 3] $ , $ [1, 1, 1] $ and $ [5, 10] $ are dense. And the arrays $ [5, 11] $ , $ [1, 4, 2] $ , $ [6, 6, 1] $ are **not** dense. You are given an array $ a $ of $ n $ integers. What is the minimum number of numbers you need to add to an array to make it dense? You can insert numbers anywhere in the array. If the array is already dense, no numbers need to be added. For example, if $a=[4,2,10,1]$ , then the answer is $ 5 $ , and the array itself after inserting elements into it may look like this: $ a=[4,2,\underline{\textbf{3}},\underline{\textbf{5}},10,\underline{\textbf{6}},\underline{\textbf{4}},\underline{\textbf{2}},1] $ (there are other ways to build such $ a$).

输入输出格式

输入格式


The first line contains one integer $ t $ ( $ 1 \le t \le 1000 $ ). Then $ t $ test cases follow. The first line of each test case contains one integer $ n $ ( $ 2 \le n \le 50 $ ) — the length of the array $ a $ . The next line contains $ n $ integers $ a_1, a_2, \ldots, a_n $ ( $ 1 \le a_i \le 50 $ ).

输出格式


For each test case, output one integer — the minimum number of numbers that must be added to the array to make it dense.

输入输出样例

输入样例 #1

6
4
4 2 10 1
2
1 3
2
6 1
3
1 4 2
5
1 2 3 4 3
12
4 31 25 50 30 20 34 46 42 16 15 16

输出样例 #1

5
1
2
1
0
3

说明

The first test case is explained in the statements. In the second test case, you can insert one element, $ a=[1,\underline{\textbf{2}},3] $ . In the third test case, you can insert two elements, $ a=[6,\underline{\textbf{4}},\underline{\textbf{2}},1] $ . In the fourth test case, you can insert one element, $ a=[1,\underline{\textbf{2}},4,2] $ . In the fifth test case, the array $ a $ is already dense.

Input

题意翻译

如果序列 $a$ 的任意相邻两项中,较大者不大于较小者的二倍,则 Polycarp 称 $a$ 是一个密集序列。形式化地,序列 $a$ 是密集的,等价于 $$\forall\ 1 \leqslant i < n, \frac{\max(a_i, a_{i + 1})}{\min(a_i, a_{i + 1})} \leqslant 2.$$ 例如:序列 $[1, 2, 3, 4, 3]$、$[1, 1, 1]$、$[5, 10]$ 是密集的;序列 $[5, 11]$、$[1, 4, 2]$、$[6, 6, 1]$ 不是密集的。 你有一个序列 $a$,你可以在其任意位置插入任意正整数,求最少需要插入多少个数才能使 $a$ 变为密集的。 例如:$a = [4, 2, 10, 1]$,则答案为 $5$,插入后的序列可以为 $a' = [4, 2, \underline 3, \underline 5, 10, \underline 6, \underline 4, \underline 2, 1]$。当然还有其他插入数的方式。 $1 \leqslant t \leqslant 1000$,$1 \leqslant n \leqslant 50$,$1 \leqslant a_i \leqslant 50$。 Translated by [KHIN](/user/236807).

加入题单

算法标签: