A15107 | Patchouli's Magical Talisman
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
She is skilled in all kinds of magics, and is keen on inventing new one.
—Perfect Memento in Strict Sense
Patchouli is making a magical talisman. She initially has $n$ magical tokens. Their magical power can be represented with positive integers $a_1, a_2, \ldots, a_n$ .
Patchouli may perform the following two operations on the tokens.
- Fusion: Patchouli chooses two tokens, removes them, and creates a new token with magical power equal to the sum of the two chosen tokens.
- Reduction: Patchouli chooses a token with an even value of magical power $x$ , removes it and creates a new token with magical power equal to $\frac{x}{2}$ .
Tokens are more effective when their magical powers are odd values. Please help Patchouli to find the minimum number of operations she needs to make magical powers of all tokens odd values.
—Perfect Memento in Strict Sense
Patchouli is making a magical talisman. She initially has $n$ magical tokens. Their magical power can be represented with positive integers $a_1, a_2, \ldots, a_n$ .
Patchouli may perform the following two operations on the tokens.
- Fusion: Patchouli chooses two tokens, removes them, and creates a new token with magical power equal to the sum of the two chosen tokens.
- Reduction: Patchouli chooses a token with an even value of magical power $x$ , removes it and creates a new token with magical power equal to $\frac{x}{2}$ .
Tokens are more effective when their magical powers are odd values. Please help Patchouli to find the minimum number of operations she needs to make magical powers of all tokens odd values.
输入格式
Each test contains multiple test cases.
The first line contains a single integer $t$ ( $1 \leq t \leq 10^3$ ) — the number of test cases. The description of the test cases follows.
For each test case, the first line contains one integer $n$ ( $1 \leq n\leq 2\cdot 10^5$ ) — the initial number of tokens.
The second line contains $n$ intergers $a_1,a_2,\ldots,a_n$ ( $1 \leq a_i \leq 10^9$ ) — the initial magical power of the $n$ tokens.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$ .
The first line contains a single integer $t$ ( $1 \leq t \leq 10^3$ ) — the number of test cases. The description of the test cases follows.
For each test case, the first line contains one integer $n$ ( $1 \leq n\leq 2\cdot 10^5$ ) — the initial number of tokens.
The second line contains $n$ intergers $a_1,a_2,\ldots,a_n$ ( $1 \leq a_i \leq 10^9$ ) — the initial magical power of the $n$ tokens.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$ .
输出格式
For each test case, print a single integer — the minimum number of operations Patchouli needs to make all tokens have an odd value of magical power.
It can be shown that under such restrictions the required sequence of operations exists.
It can be shown that under such restrictions the required sequence of operations exists.
输入输出样例
输入 #1
4 2 1 9 3 1 1 2 3 2 4 8 3 1049600 33792 1280
输出 #1
0 1 3 10
Test case 1:
$a$ consists solely of odd numbers initially.
Test case 2:
Choose the tokens with magical power of $1$ and $2$ and perform Fusion. Now $a=[1,3]$ , both are odd numbers.
Test case 3:
Choose the tokens with magical power of $2$ and $8$ and perform Fusion. Now $a=[4,10]$ .
Choose the token with magical power of $10$ and perform Reduction. Now $a=[4,5]$ .
Choose the tokens with magical power of $4$ and $5$ and perform Fusion. Now $a=[9]$ , and $9$ is an odd number.
It can be shown that you can not make all the magical powers odd numbers in less than $3$ moves, so the answer is $3$ .
$a$ consists solely of odd numbers initially.
Test case 2:
Choose the tokens with magical power of $1$ and $2$ and perform Fusion. Now $a=[1,3]$ , both are odd numbers.
Test case 3:
Choose the tokens with magical power of $2$ and $8$ and perform Fusion. Now $a=[4,10]$ .
Choose the token with magical power of $10$ and perform Reduction. Now $a=[4,5]$ .
Choose the tokens with magical power of $4$ and $5$ and perform Fusion. Now $a=[9]$ , and $9$ is an odd number.
It can be shown that you can not make all the magical powers odd numbers in less than $3$ moves, so the answer is $3$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted