306927: CF1272A. Three Friends

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Three Friends

题意翻译

## 题目描述 有三个人站在一个平面直角坐标系的$x$轴上,他们的纵坐标分别为$a,b,c$ 定义这三个的距离和为$|a-b|+|b-c|+|a-c|$ 接下来的一分钟,他们每一个人可以选择:向左走一个单位长度 或 向右走一个单位长度,求一分钟后的三个人的最小距离和 ## 输入格式 第一行一个整数$q$,表示有$q$组数据 接下来$q$行,每行三个整数$a,b,c$,如题所述 ## 输出格式 $q$行,每行一个整数,对应每组数据,表示一分钟后三个人的最小距离和 ### 数据范围: $1\leq q \le 1000$ $1\leq a,b,c \le 10^9$ 感谢 @_Wolverine 提供的翻译

题目描述

Three friends are going to meet each other. Initially, the first friend stays at the position $ x = a $ , the second friend stays at the position $ x = b $ and the third friend stays at the position $ x = c $ on the coordinate axis $ Ox $ . In one minute each friend independently from other friends can change the position $ x $ by $ 1 $ to the left or by $ 1 $ to the right (i.e. set $ x := x - 1 $ or $ x := 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' $ , $ b' $ and $ 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'| $ , where $ |x| $ is the absolute value of $ x $ . 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 $ q $ independent test cases.

输入输出格式

输入格式


The first line of the input contains one integer $ q $ ( $ 1 \le q \le 1000 $ ) — the number of test cases. The next $ q $ lines describe test cases. The $ i $ -th test case is given as three integers $ a, b $ and $ c $ ( $ 1 \le a, b, c \le 10^9 $ ) — initial positions of the first, second and third friend correspondingly. The positions of friends can be equal.

输出格式


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

Input

题意翻译

## 题目描述 有三个人站在一个平面直角坐标系的$x$轴上,他们的纵坐标分别为$a,b,c$ 定义这三个的距离和为$|a-b|+|b-c|+|a-c|$ 接下来的一分钟,他们每一个人可以选择:向左走一个单位长度 或 向右走一个单位长度,求一分钟后的三个人的最小距离和 ## 输入格式 第一行一个整数$q$,表示有$q$组数据 接下来$q$行,每行三个整数$a,b,c$,如题所述 ## 输出格式 $q$行,每行一个整数,对应每组数据,表示一分钟后三个人的最小距离和 ### 数据范围: $1\leq q \le 1000$ $1\leq a,b,c \le 10^9$ 感谢 @_Wolverine 提供的翻译

加入题单

上一题 下一题 算法标签: