CF1605A.A.M. Deviation

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

A number a2a_2 is said to be the arithmetic mean of two numbers a1a_1 and a3a_3, if the following condition holds: a1+a3=2⋅a2a_1 + a_3 = 2\cdot a_2.

We define an arithmetic mean deviation of three numbers a1a_1, a2a_2 and a3a_3 as follows: d(a1,a2,a3)=∣a1+a3−2⋅a2∣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 a1a_1, a2a_2 and a3a_3 and he wants to minimize the arithmetic mean deviation d(a1,a2,a3)d(a_1, a_2, a_3). To do so, he can perform the following operation any number of times (possibly zero):

  • Choose i,ji, j from 1,2,3{1, 2, 3} such that i≠ji \ne j and increment aia_i by 11 and decrement aja_j by 11

Help Jeevan find out the minimum value of d(a1,a2,a3)d(a_1, a_2, a_3) that can be obtained after applying the operation any number of times.

若满足条件 a1+a3=2⋅a2a_1 + a_3 = 2\cdot a_2,则称数 a2a_2 为两数 a1a_1 和 a3a_3 的算术平均数。

我们定义三个数 a1a_1、a2a_2 和 a3a_3 的算术平均偏差如下:

d(a1,a2,a3)=∣a1+a3−2⋅a2∣d(a_1, a_2, a_3) = |a_1 + a_3 - 2 \cdot a_2|

算术平均对 Jeevan 来说意义重大。他手上有三个数 a1a_1、a2a_2 和 a3a_3,希望将算术平均偏差 d(a1,a2,a3)d(a_1, a_2, a_3) 最小化。为此,他可执行以下操作任意次(包括零次):

  • 从集合 {1,2,3}\{1, 2, 3\} 中选择两个不同下标 i,ji, j(即 i≠ji \ne j),将 aia_i 增加 11,同时将 aja_j 减少 11。

请帮助 Jeevan 求出:经过任意次上述操作后,d(a1,a2,a3)d(a_1, a_2, a_3) 能达到的最小值。

输入格式

The first line contains a single integer tt (1≤t≤5000)(1 \le t \le 5000) — the number of test cases.

The first and only line of each test case contains three integers a1a_1, a2a_2 and a3a_3 (1≤a1,a2,a3≤108)(1 \le a_1, a_2, a_3 \le 10^{8}).

第一行包含一个整数 tt(1≤t≤50001 \le t \le 5000)—— 表示测试用例的数量。

每个测试用例仅有一行,包含三个整数 a1a_1、a2a_2 和 a3a_3(1≤a1,a2,a3≤1081 \le a_1, a_2, a_3 \le 10^{8})。

输出格式

For each test case, output the minimum value of d(a1,a2,a3)d(a_1, a_2, a_3) that can be obtained after applying the operation any number of times.

对于每个测试用例,输出在任意次数执行该操作后所能得到的 d(a1,a2,a3)d(a_1, a_2, a_3) 的最小值。

输入输出样例

  • 输入#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 a1a_1, a2a_2 and a3a_3 may become negative.

In the first test case, 44 is already the Arithmetic Mean of 33 and 55.

d(3,4,5)=∣3+5−2⋅4∣=0d(3, 4, 5) = |3 + 5 - 2 \cdot 4| = 0

In the second test case, we can apply the following operation:

(2,2,6)(2, 2, 6) $\xrightarrow[\text{increment a_2a\_2}]{\text{decrement a_1a\_1}}$ (1,3,6)(1, 3, 6)

d(1,3,6)=∣1+6−2⋅3∣=1d(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)(1, 6, 5) $\xrightarrow[\text{increment a_3a\_3}]{\text{decrement a_2a\_2}}$ (1,5,6)(1, 5, 6) $\xrightarrow[\text{increment a_1a\_1}]{\text{decrement a_2a\_2}}$ (2,4,6)(2, 4, 6)

d(2,4,6)=∣2+6−2⋅4∣=0d(2, 4, 6) = |2 + 6 - 2 \cdot 4| = 0

注意:在执行若干次操作后,a1a_1、a2a_2 和 a3a_3 的值可能变为负数。

在第一个测试用例中,44 已经是 33 和 55 的算术平均数。

d(3,4,5)=∣3+5−2⋅4∣=0d(3, 4, 5) = |3 + 5 - 2 \cdot 4| = 0

在第二个测试用例中,我们可以执行以下操作:

(2,2,6)(2, 2, 6) $\xrightarrow[\text{对 a_2a\_2 执行加 1 操作}]{\text{对 a_1a\_1 执行减 1 操作}}$ (1,3,6)(1, 3, 6)

d(1,3,6)=∣1+6−2⋅3∣=1d(1, 3, 6) = |1 + 6 - 2 \cdot 3| = 1

可以证明该答案已无法进一步优化。

在第三个测试用例中,我们可以执行以下操作:

(1,6,5)(1, 6, 5) $\xrightarrow[\text{对 a_3a\_3 执行加 1 操作}]{\text{对 a_2a\_2 执行减 1 操作}}$ (1,5,6)(1, 5, 6) $\xrightarrow[\text{对 a_1a\_1 执行加 1 操作}]{\text{对 a_2a\_2 执行减 1 操作}}$ (2,4,6)(2, 4, 6)

d(2,4,6)=∣2+6−2⋅4∣=0d(2, 4, 6) = |2 + 6 - 2 \cdot 4| = 0

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

首页