A14292 | Arithmetic Array
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
An array $b$ of length $k$ is called good if its arithmetic mean is equal to $1$ . More formally, if $$$$\frac{b_1 + \cdots + b_k}{k}=1. $$ </p><p>Note that the value $\\frac{b\_1+\\cdots+b\_k}{k}$ is not rounded up or down. For example, the array $\[1,1,1,2\]$ has an arithmetic mean of $1.25$ , which is not equal to $1$ .</p><p>You are given an integer array $a$ of length $n$$$. In an operation, you can append a non-negative integer to the end of the array. What's the minimum number of operations required to make the array good?
We have a proof that it is always possible with finitely many operations.
We have a proof that it is always possible with finitely many operations.
输入格式
The first line contains a single integer $t$ ( $1 \leq t \leq 1000$ ) — the number of test cases. Then $t$ test cases follow.
The first line of each test case contains a single integer $n$ ( $1 \leq n \leq 50$ ) — the length of the initial array $a$ .
The second line of each test case contains $n$ integers $a_1,\ldots,a_n$ ( $-10^4\leq a_i \leq 10^4$ ), the elements of the array.
The first line of each test case contains a single integer $n$ ( $1 \leq n \leq 50$ ) — the length of the initial array $a$ .
The second line of each test case contains $n$ integers $a_1,\ldots,a_n$ ( $-10^4\leq a_i \leq 10^4$ ), the elements of the array.
输出格式
For each test case, output a single integer — the minimum number of non-negative integers you have to append to the array so that the arithmetic mean of the array will be exactly $1$ .
输入输出样例
输入 #1
4 3 1 1 1 2 1 2 4 8 4 6 2 1 -2
输出 #1
0 1 16 1
In the first test case, we don't need to add any element because the arithmetic mean of the array is already $1$ , so the answer is $0$ .
In the second test case, the arithmetic mean is not $1$ initially so we need to add at least one more number. If we add $0$ then the arithmetic mean of the whole array becomes $1$ , so the answer is $1$ .
In the third test case, the minimum number of elements that need to be added is $16$ since only non-negative integers can be added.
In the fourth test case, we can add a single integer $4$ . The arithmetic mean becomes $\frac{-2+4}{2}$ which is equal to $1$ .
In the second test case, the arithmetic mean is not $1$ initially so we need to add at least one more number. If we add $0$ then the arithmetic mean of the whole array becomes $1$ , so the answer is $1$ .
In the third test case, the minimum number of elements that need to be added is $16$ since only non-negative integers can be added.
In the fourth test case, we can add a single integer $4$ . The arithmetic mean becomes $\frac{-2+4}{2}$ which is equal to $1$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted