A14567 | A.M. Deviation
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
A number $a_2$ is said to be the arithmetic mean of two numbers $a_1$ and $a_3$ , if the following condition holds: $a_1 + a_3 = 2\cdot a_2$ .
We define an arithmetic mean deviation of three numbers $a_1$ , $a_2$ and $a_3$ as follows: $d(a_1, a_2, a_3) = |a_1 + a_3 - 2 \cdot a_2|$ .
Arithmetic means a lot to Jeevan. He has three numbers $a_1$ , $a_2$ and $a_3$ and he wants to minimize the arithmetic mean deviation $d(a_1, a_2, a_3)$ . To do so, he can perform the following operation any number of times (possibly zero):
- Choose $i, j$ from $\{1, 2, 3\}$ such that $i \ne j$ and increment $a_i$ by $1$ and decrement $a_j$ by $1$
Help Jeevan find out the minimum value of $d(a_1, a_2, a_3)$ that can be obtained after applying the operation any number of times.
We define an arithmetic mean deviation of three numbers $a_1$ , $a_2$ and $a_3$ as follows: $d(a_1, a_2, a_3) = |a_1 + a_3 - 2 \cdot a_2|$ .
Arithmetic means a lot to Jeevan. He has three numbers $a_1$ , $a_2$ and $a_3$ and he wants to minimize the arithmetic mean deviation $d(a_1, a_2, a_3)$ . To do so, he can perform the following operation any number of times (possibly zero):
- Choose $i, j$ from $\{1, 2, 3\}$ such that $i \ne j$ and increment $a_i$ by $1$ and decrement $a_j$ by $1$
Help Jeevan find out the minimum value of $d(a_1, a_2, a_3)$ that can be obtained after applying the operation any number of times.
输入格式
The first line contains a single integer $t$ $(1 \le t \le 5000)$ — the number of test cases.
The first and only line of each test case contains three integers $a_1$ , $a_2$ and $a_3$ $(1 \le a_1, a_2, a_3 \le 10^{8})$ .
The first and only line of each test case contains three integers $a_1$ , $a_2$ and $a_3$ $(1 \le a_1, a_2, a_3 \le 10^{8})$ .
输出格式
For each test case, output the minimum value of $d(a_1, a_2, a_3)$ that can be obtained after applying the operation any number of times.
输入输出样例
输入 #1
3 3 4 5 2 2 6 1 6 5
输出 #1
0 1 0
Note that after applying a few operations, the values of $a_1$ , $a_2$ and $a_3$ may become negative.
In the first test case, $4$ is already the Arithmetic Mean of $3$ and $5$ .
$d(3, 4, 5) = |3 + 5 - 2 \cdot 4| = 0$
In the second test case, we can apply the following operation:
$(2, 2, 6)$ $\xrightarrow[\text{increment $ a\_2 $}]{\text{decrement $ a\_1 $}}$ $(1, 3, 6)$
$d(1, 3, 6) = |1 + 6 - 2 \cdot 3| = 1$
It can be proven that answer can not be improved any further.
In the third test case, we can apply the following operations:
$(1, 6, 5)$ $\xrightarrow[\text{increment $ a\_3 $}]{\text{decrement $ a\_2 $}}$ $(1, 5, 6)$ $\xrightarrow[\text{increment $ a\_1 $}]{\text{decrement $ a\_2 $}}$ $(2, 4, 6)$
$d(2, 4, 6) = |2 + 6 - 2 \cdot 4| = 0$
In the first test case, $4$ is already the Arithmetic Mean of $3$ and $5$ .
$d(3, 4, 5) = |3 + 5 - 2 \cdot 4| = 0$
In the second test case, we can apply the following operation:
$(2, 2, 6)$ $\xrightarrow[\text{increment $ a\_2 $}]{\text{decrement $ a\_1 $}}$ $(1, 3, 6)$
$d(1, 3, 6) = |1 + 6 - 2 \cdot 3| = 1$
It can be proven that answer can not be improved any further.
In the third test case, we can apply the following operations:
$(1, 6, 5)$ $\xrightarrow[\text{increment $ a\_3 $}]{\text{decrement $ a\_2 $}}$ $(1, 5, 6)$ $\xrightarrow[\text{increment $ a\_1 $}]{\text{decrement $ a\_2 $}}$ $(2, 4, 6)$
$d(2, 4, 6) = |2 + 6 - 2 \cdot 4| = 0$
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted