CF1735B.Tea with Tangerines

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

There are nn pieces of tangerine peel, the ii-th of them has size aia_i. In one step it is possible to divide one piece of size xx into two pieces of positive integer sizes yy and zz so that y+z=xy + z = x.

You want that for each pair of pieces, their sizes differ strictly less than twice. In other words, there should not be two pieces of size xx and yy, such that 2x≤y2x \le y. What is the minimum possible number of steps needed to satisfy the condition?

有 nn 块橘子皮,其中第 ii 块的大小为 aia_i。每一步操作中,你可以将一块大小为 xx 的橘子皮分割成两块大小分别为 yy 和 zz 的橘子皮,其中 yy 和 zz 均为正整数,且满足 y+z=xy + z = x。

你希望任意两块橘子皮的大小之差严格小于二者中较小者大小的两倍。换言之,不能存在两块大小分别为 xx 和 yy 的橘子皮,使得 2x≤y2x \le y。问:满足该条件所需的最少操作步数是多少?

输入格式

The first line of the input contains a single integer tt (1≤t≤1001 \le t \le 100) — the number of test cases. The description of test cases follows.

The first line of each test case contains the integer nn (1≤n≤1001 \le n \le 100).

Then one line follows, containing nn integers a1≤a2≤…≤ana_1 \le a_2 \le \ldots \le a_n (1≤ai≤1071 \le a_i \le 10^7).

输入的第一行包含一个整数 tt(1≤t≤1001 \le t \le 100)—— 表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤1001 \le n \le 100)。

接下来的一行包含 nn 个整数 a1≤a2≤…≤ana_1 \le a_2 \le \ldots \le a_n(1≤ai≤1071 \le a_i \le 10^7)。

输出格式

For each test case, output a single line containing the minimum number of steps.

对于每个测试用例,输出一行,包含最少步数。

输入输出样例

  • 输入#1

    3
    5
    1 2 3 4 5
    1
    1033
    5
    600 900 1300 2000 2550

    输出#1

    10
    0
    4

说明/提示

In the first test case, we initially have a piece of size 11, so all final pieces must have size 11. The total number of steps is: 0+1+2+3+4=100 + 1 + 2 + 3 + 4 = 10.

In the second test case, we have just one piece, so we don't need to do anything, and the answer is 00 steps.

In the third test case, one of the possible cut options is: 600, 900, (600∣700), (1000∣1000), (1000∣1000∣550)600,\ 900,\ (600 | 700),\ (1000 | 1000),\ (1000 | 1000 | 550). You can see this option in the picture below. The maximum piece has size 10001000, and it is less than 22 times bigger than the minimum piece of size 550550. 44 steps are done. We can show that it is the minimum possible number of steps.

在第一个测试用例中,我们初始拥有一块大小为 11 的木块,因此所有最终木块的大小都必须为 11。总操作步数为:0+1+2+3+4=100 + 1 + 2 + 3 + 4 = 10。

在第二个测试用例中,我们仅有一块木块,因此无需进行任何操作,答案为 00 步。

在第三个测试用例中,一种可能的切割方案是:600, 900, (600∣700), (1000∣1000), (1000∣1000∣550)600,\ 900,\ (600 | 700),\ (1000 | 1000),\ (1000 | 1000 | 550)。您可在下方图片中看到该方案。其中最大木块大小为 10001000,小于最小木块大小 550550 的两倍。共进行了 44 步操作。可以证明这是最少的操作步数。

输入解题思路,AI测评打分。不知道怎么写?

首页