Codeforces 723A-The New Year: Meeting Friends
2016-11-15 15:21
3479 查看
A. The New Year: Meeting Friends
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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.
Input
The 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.
Output
Print one integer — the minimum total distance the friends need to travel in order to meet together.
Examples
input
output
input
output
Note
In 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.
题意:
找出与其相隔距离和最小的那个点。
解:
排序之后找出中间那个数就是。
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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.
Input
The 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.
Output
Print one integer — the minimum total distance the friends need to travel in order to meet together.
Examples
input
7 1 4
output
6
input
30 20 10
output
20
Note
In 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.
题意:
找出与其相隔距离和最小的那个点。
解:
排序之后找出中间那个数就是。
#include <stdio.h> #include <algorithm> #include <iostream> using namespace std; int main() { int a[3]; while(~scanf("%d%d%d",&a[0],&a[1],&a[2])) { int sum=0; sort(a,a+3); for(int i=0;i<2;i++) sum+=a[i+1]-a[i]; printf("%d\n",sum); } return 0; }
相关文章推荐
- CodeForces 723A-The New Year: Meeting Friends(很水)
- Codeforces The New Year: Meeting Friends
- 【Codeforces Round 375 (Div 2) A】【水题】The New Year Meeting Friends
- CodeForces - 723A - A. The New Year: Meeting Friends
- CodeForces723-A. The New Year: Meeting Friends
- 【69.77%】【codeforces 723A】The New Year: Meeting Friends
- codeforces 723A : The New Year: Meeting Friends
- codeforces——723A—— The New Year: Meeting Friends
- The New Year: Meeting Friends Codeforces Round#375-A
- [codeforces]A. The New Year: Meeting Friends 水题
- Codeforce 723A - The New Year: Meeting Friends
- CodeForces - 723A A. The New Year: Meeting Friends
- 【CodeForces】908 D. New Year and Arbitrary Arrangement
- 【CodeForces】500B - New Year Permutation(Floyd)(贪心)
- Codeforces Good bye 2015 B. New Year and Old Property dfs 数位DP
- 【codeforces 782B】The Meeting Place Cannot Be Changed(二分)
- Codeforces 611 E New Year and Three Musketeers
- codeforces 140 A. New Year Table
- 【codeforces】New Year Book Reading
- Codeforces Good Bye 2017 A - New Year and Counting Cards