CF1272A.Three Friends

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Three friends are going to meet each other. Initially, the first friend stays at the position x=ax = a, the second friend stays at the position x=bx = b and the third friend stays at the position x=cx = c on the coordinate axis OxOx.

In one minute each friend independently from other friends can change the position xx by 11 to the left or by 11 to the right (i.e. set x:=x−1x := x - 1 or x:=x+1x := x + 1) or even don't change it.

Let's introduce the total pairwise distance — the sum of distances between each pair of friends. Let a′a', b′b' and c′c' be the final positions of the first, the second and the third friend, correspondingly. Then the total pairwise distance is ∣a′−b′∣+∣a′−c′∣+∣b′−c′∣|a' - b'| + |a' - c'| + |b' - c'|, where ∣x∣|x| is the absolute value of xx.

Friends are interested in the minimum total pairwise distance they can reach if they will move optimally. Each friend will move no more than once. So, more formally, they want to know the minimum total pairwise distance they can reach after one minute.

You have to answer qq independent test cases.

三位朋友将要彼此会面。最初,第一位朋友位于坐标轴 OxOx 上的位置 x=ax = a,第二位朋友位于位置 x=bx = b,第三位朋友位于位置 x=cx = c。

每一分钟,每位朋友均可独立于其他朋友,将自身位置 xx 向左移动 11(即令 x:=x−1x := x - 1),或向右移动 11(即令 x:=x+1x := x + 1),或者保持不动。

我们定义总两两距离为每对朋友之间距离之和。设 a′a'、b′b' 和 c′c' 分别为第一位、第二位和第三位朋友的最终位置,则总两两距离为 ∣a′−b′∣+∣a′−c′∣+∣b′−c′∣|a' - b'| + |a' - c'| + |b' - c'|,其中 ∣x∣|x| 表示 xx 的绝对值。

朋友们希望知道:若他们以最优方式移动,所能达到的最小总两两距离是多少。每位朋友最多移动一次。更准确地说,他们希望求出经过一分钟之后所能达到的最小总两两距离。

你需要回答 qq 个相互独立的测试用例。

输入格式

The first line of the input contains one integer qq (1≤q≤10001 \le q \le 1000) — the number of test cases.

The next qq lines describe test cases. The ii-th test case is given as three integers a,ba, b and cc (1≤a,b,c≤1091 \le a, b, c \le 10^9) — initial positions of the first, second and third friend correspondingly. The positions of friends can be equal.

输入的第一行包含一个整数 qq(1≤q≤10001 \le q \le 1000),表示测试用例的数量。

接下来的 qq 行描述了各个测试用例。第 ii 个测试用例由三个整数 a,ba, b 和 cc(1≤a,b,c≤1091 \le a, b, c \le 10^9)给出,分别表示第一位、第二位和第三位朋友的初始位置。朋友的位置可以相等。

输出格式

For each test case print the answer on it — the minimum total pairwise distance (the minimum sum of distances between each pair of friends) if friends change their positions optimally. Each friend will move no more than once. So, more formally, you have to find the minimum total pairwise distance they can reach after one minute.

对于每个测试用例,输出其答案——即朋友们在最优调整位置后所能达到的最小两两间总距离(即所有朋友对之间距离之和的最小值)。每位朋友最多移动一次。更准确地说,你需要求出在一分钟之后他们所能达到的最小两两间总距离。

输入输出样例

  • 输入#1

    8
    3 3 4
    10 20 30
    5 5 5
    2 4 3
    1 1000000000 1000000000
    1 1000000000 999999999
    3 2 5
    3 2 6

    输出#1

    0
    36
    0
    0
    1999999994
    1999999994
    2
    4

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

首页