There are three friend living on the straight line Ox in Lineland. The first friend lives at the point x1, the second friend lives at the point x2, and the third friend lives at the point x3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they have to travel in order to meet at some point and celebrate the New Year?It's guaranteed that the optimal answer is always integer.InputThe first line of the input contains three distinct integers x1, x2 and x3 (1 ≤ x1, x2, x3 ≤ 100) — the coordinates of the houses of the first, the second and the third friends respectively.OutputPrint one integer — the minimum total distance the friends need to travel in order to meet together.ExamplesinputCopy7 1 4outputCopy6inputCopy30 20 10outputCopy20NoteIn the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4.
Question
There are three friend living on the straight line Ox in Lineland. The first friend lives at the point x1, the second friend lives at the point x2, and the third friend lives at the point x3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they have to travel in order to meet at some point and celebrate the New Year?It's guaranteed that the optimal answer is always integer.InputThe first line of the input contains three distinct integers x1, x2 and x3 (1 ≤ x1, x2, x3 ≤ 100) — the coordinates of the houses of the first, the second and the third friends respectively.OutputPrint one integer — the minimum total distance the friends need to travel in order to meet together.ExamplesinputCopy7 1 4outputCopy6inputCopy30 20 10outputCopy20NoteIn the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4.
Solution
The problem is asking for the minimum total distance three friends need to travel to meet at a point. The friends live on a straight line and their houses are located at distinct points x1, x2, and x3.
Here are the steps to solve this problem:
-
First, we need to find the house that is in the middle of the other two. This is because the total distance will be minimized if they meet at the house that is in the middle.
-
To find the house in the middle
Similar Questions
Ajay was walking along a straight and narrow road. He stopped at a point and looked ahead and noticed that there were three stones, in a straight line, along the road, situated at a distance of 5 m, 6.6 m and 7.8 m from him. How much further should Ajay walk (in m) in order to minimise the sum of the distances of the three of stones from him?Enter your answer as a decimal value, rounded off to two decimal places.
Initially, you are at the position x = 1.5 m and your friend is at the position x = 11.5 m. You both walk towards each other until you meet. If you walk three times the distance that your friend walks. Where do you both meet?
You are in a city 🌇 represented by a coordinate plane. Your friend is located at a point where the X-coordinate is 3 and the Y-coordinate is 5. Another friend is located at a point with an X-coordinate of 0 and a Y-coordinate of 2. Identify the ordered pairs for both friends' locations.( 5, 3) and (2, 0)( 3, 5) and (0, 2)( 3, 0) and (5, 2)( 0, 3) and (2, 5)
A walks for 4m from point X in the East direction. He then takes a right and a left turn and walked for 3 m and 2 m respectively and finally reaches point Z. B starts walking from point Y and walks for 8 m in East direction, he then takes three consecutive right turns and walks 10 m, 2 m and 3 m respectively and reaches Z. What is shortest distance between point X and point Y?
wo friends decide to walk towards each other from opposite ends of a 52 km road. Leo can walk 6 km in one hour and Roma can walk 7 km in one hour. They both start walking at the same time.How many hours will pass between when they start walking and when they meet?Type your answer as a number without units.
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.