CF1490A.Dense Array

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 ii ( 1in11 \le i \le n-1 ), this condition must be satisfied: max(a[i],a[i+1])min(a[i],a[i+1])2\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, 2, 3, 4, 3] , [1,1,1][1, 1, 1] and [5,10][5, 10] are dense. And the arrays [5,11][5, 11] , [1,4,2][1, 4, 2] , [6,6,1][6, 6, 1] are not dense.

You are given an array aa of nn 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]a=[4,2,10,1] , then the answer is 55 , and the array itself after inserting elements into it may look like this:
a=[4,2,3,5,10,6,4,2,1]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 aa).

输入格式

The first line contains one integer tt ( 1t10001 \le t \le 1000 ). Then tt test cases follow.

The first line of each test case contains one integer nn ( 2n502 \le n \le 50 ) — the length of the array aa .

The next line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n ( 1ai501 \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,2,3]a=[1,\underline{\textbf{2}},3] .

In the third test case, you can insert two elements, a=[6,4,2,1]a=[6,\underline{\textbf{4}},\underline{\textbf{2}},1] .

In the fourth test case, you can insert one element, a=[1,2,4,2]a=[1,\underline{\textbf{2}},4,2] .

In the fifth test case, the array aa is already dense.

首页