codeforces 723A : The New Year: Meeting Friends

Description

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.

正解:模拟

解题报告:

  水题,模拟即可。

 1 //It is made by jump~
 2 #include <iostream>
 3 #include <cstdlib>
 4 #include <cstring>
 5 #include <cstdio>
 6 #include <cmath>
 7 #include <algorithm>
 8 #include <ctime>
 9 #include <vector>
10 #include <queue>
11 #include <map>
12 #include <set>
13 using namespace std;
14 typedef long long LL;
15 const int inf = (1<<30);
16 int a[4];
17 int pos;
18 int ans;
19
20 inline int getint()
21 {
22     int w=0,q=0; char c=getchar();
23     while((c<‘0‘ || c>‘9‘) && c!=‘-‘) c=getchar(); if(c==‘-‘) q=1,c=getchar();
24     while (c>=‘0‘ && c<=‘9‘) w=w*10+c-‘0‘, c=getchar(); return q ? -w : w;
25 }
26
27 inline void work(){
28     for(int i=1;i<=3;i++) a[i]=getint();
29     sort(a+1,a+4); ans+=a[2]-a[1]; ans+=a[3]-a[2];
30     printf("%d",ans);
31 }
32
33 int main()
34 {
35     work();
36     return 0;
37 }
时间: 2024-10-11 16:05:42

codeforces 723A : The New Year: Meeting Friends的相关文章

CodeForces 723A The New Year: Meeting Friends (水题)

题意:给定 3 个数,求其中一个数到另外两个数之间的最短距离. 析:很明显选中间那个点了. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream> #include <cs

Jury Meeting CodeForces - 854D

Jury Meeting CodeForces - 854D 思路:暴力枚举会议开始的那一天(只需用所有向0点飞的航班的那一天+1去枚举即可),并计算所有人此情况下去0点和从0点出来的最小花费. 具体:首先,将航班分为飞入0和飞出0两类. 然后,枚举会议开始的时间p. 那么,飞入0的航班只有时间<p的生效,飞出0的航班只有时间>p+k-1的生效. 显然,在p变为p+1时,最多只有各一班航班生效与失效. (听说还能二分,但是已经打了100行了,不敢再加了...好累) 1 #include<

Codeforces 238E. Meeting Her 图论+记忆化搜索

大意: 有一个 n 个结点的有向图,边权均为 1.Urapl 想从 a 出发去 b.有 p 个公交车公司.在每 一秒的开始,第 i 个公司的公交车随机选择一条从 s i 到 t i 的最短路径然后走这条路径.如果 一个公交车经过 Urpal 所在的交叉点,则 Urpal 可以上这辆公交车,他可以在中途任意一个结 点下车. 在任何时刻 Urpal 只知道他自己的位置和约会地点.当他上了公交车时他只知道这辆公交 车属于第几个公司.当然 Urpal 知道城市地图和每个公司的 (s i , t i ).

codeforces 782B The Meeting Place Cannot Be Changed+hdu 4355+hdu 2438 (三分)

B. The Meeting Place Cannot Be Changed The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction. At some points on the road there are n

Codeforces 714A. Meeting of Old Friends

题目链接:http://codeforces.com/problemset/problem/714/A 题意: 一个猫头鹰可以在时间段 l1 到 r1 处于清醒状态, 且需要在 k 时为自己化妆,在 l2 到 r2 时间段去访问自己的朋友, 问它能和自己的朋友在一起待多久时间. 思路: 设呆在一起的时间为 anst, 则 anst = min(r1, r2) - max(l1, l2) + 1,如果 k 处于 min(r1, r2) 和 max(l1, l2) 之间, 则还需要减去化妆的一刻:

【CodeForces - 238E】Meeting Her(图论+记忆化搜索)

Description 题目链接:Codeforces Solution 因为路线随机,所以找出各路线最短路必须经过的点,在这个点必定能上车 直接floyd暴力找割点 然后不断用k条公交车路线来更新DP答案,直到更新不了为止,dp[i]表示从点i到终点的答案 Code #include <cstdio> #include <algorithm> #include <cstring> #define N 1100 using namespace std; int n,m,

Jury Meeting CodeForces - 854D (前缀和维护)

Country of Metropolia is holding Olympiad of Metrpolises soon. It mean that all jury members of the olympiad should meet together in Metropolis (the capital of the country) for the problem preparation process. There are n + 1 cities consecutively num

codeforces 782B - The Meeting Place Cannot Be Changed

题意: 一条线上有n个人,每个人一个坐标值xi,每个人有一个最大行走速度vi,问如果要让这n个人走到线上某一个点,最少需要多少时间. 分析: 看起来是二分, 二分坐标. 二分区间变化的条件,一开始感觉是比较当前mid坐标左右人们用最快速度到达的平均时间, 后来具体写的时候感觉是比较当前mid坐标左右人们用最快速度到达的最大时间. 其实就是后者. 如果某一边的最大时间比较大的话,坐标就要向那一边偏移, 最后循环退出的条件就是在误差以内. 代码: 1 #include <set> 2 #inclu

Codeforces 853B Jury Meeting

题意 从城市1-n来的评审团到城市0商讨国家大事,离开和抵达的那一天不能讨论,飞机均当天抵达,给出所有飞机起飞抵达代价情况,问能否使所有评审员聚齐连续k天并返回,并求最小代价 思路 从前向后扫一遍,求每天的出发最小代价L[i],从后向前扫,求每天最小离开代价R[i] 从前向后扫一遍,每天的最小代价为L[i]+R[i+k+1] 将每天的默认大小设为1e12,因为最大代价不超过1e11,可以据此确定答案是否合法 代码 #include<bits/stdc++.h> using namespace