CF1762A.Divide and Conquer

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

An array bb is good if the sum of elements of bb is even.

You are given an array aa consisting of nn positive integers. In one operation, you can select an index ii and change ai:=⌊ai2⌋a_i := \lfloor \frac{a_i}{2} \rfloor. †^\dagger

Find the minimum number of operations (possibly 00) needed to make aa good. It can be proven that it is always possible to make aa good.

†^\dagger ⌊x⌋\lfloor x \rfloor denotes the floor function — the largest integer less than or equal to xx. For example, ⌊2.7⌋=2\lfloor 2.7 \rfloor = 2, ⌊π⌋=3\lfloor \pi \rfloor = 3 and ⌊5⌋=5\lfloor 5 \rfloor =5.

若数组 bb 的元素之和为偶数,则称 bb 是“好”的。

给定一个由 nn 个正整数构成的数组 aa。在一次操作中,你可以选择一个下标 ii,并将 aia_i 修改为 ⌊ai2⌋\lfloor \frac{a_i}{2} \rfloor。†^\dagger

求使 aa 变为“好”的数组所需的最少操作次数(可以为 00)。可以证明:总能通过若干次操作使 aa 变为“好”的数组。

†^\dagger ⌊x⌋\lfloor x \rfloor 表示向下取整函数——即不超过 xx 的最大整数。例如,⌊2.7⌋=2\lfloor 2.7 \rfloor = 2,⌊π⌋=3\lfloor \pi \rfloor = 3,⌊5⌋=5\lfloor 5 \rfloor = 5。

输入格式

Each test contains multiple test cases. The first line contains a single integer tt (1≤t≤10001 \leq t \leq 1000) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer nn (1≤n≤501 \leq n \leq 50) — the length of the array aa.

The second line of each test case contains nn space-separated integers a1,a2,…,ana_1,a_2,\ldots,a_n (1≤ai≤1061 \leq a_i \leq 10^6) — representing the array aa.

Do note that the sum of nn over all test cases is not bounded.

每个测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤10001 \leq t \leq 1000),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤501 \leq n \leq 50),表示数组 aa 的长度。

每个测试用例的第二行包含 nn 个以空格分隔的整数 a1,a2,…,ana_1,a_2,\ldots,a_n(1≤ai≤1061 \leq a_i \leq 10^6),表示数组 aa。

请注意,所有测试用例的 nn 之和没有上界。

输出格式

For each test case, output the minimum number of operations needed to make aa good.

对于每个测试用例,输出使 aa 变为“好”的数组所需的最少操作次数。

输入输出样例

  • 输入#1

    4
    4
    1 1 1 1
    2
    7 4
    3
    1 2 4
    1
    15

    输出#1

    0
    2
    1
    4

说明/提示

In the first test case, array aa is already good.

In the second test case, we can perform on index 22 twice. After the first operation, array aa becomes [7,2][7,2]. After performing on index 22 again, aa becomes [7,1][7,1], which is good. It can be proved that it is not possible to make aa good in less number of operations.

In the third test case, aa becomes [0,2,4][0,2,4] if we perform the operation on index 11 once. As [0,2,4][0,2,4] is good, answer is 11.

In the fourth test case, we need to perform the operation on index 11 four times. After all operations, aa becomes [0][0]. It can be proved that it is not possible to make aa good in less number of operations.

在第一个测试用例中,数组 aa 已经是“好”的。

在第二个测试用例中,我们可以在下标 22 处执行操作两次。第一次操作后,数组 aa 变为 [7,2][7,2];再次对下标 22 执行操作后,aa 变为 [7,1][7,1],此时它是“好”的。可以证明,无法用少于两次的操作使 aa 变为“好”的。

在第三个测试用例中,若对下标 11 执行一次操作,则 aa 变为 [0,2,4][0,2,4]。由于 [0,2,4][0,2,4] 是“好”的,因此答案为 11。

在第四个测试用例中,我们需要对下标 11 执行四次操作。所有操作完成后,aa 变为 [0][0]。可以证明,无法用少于四次的操作使 aa 变为“好”的。

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

首页