Codeforces Round #375 (Div. 2) A. The New Year: Meeting Friends 水题

时间:2022-07-03 10:07:55

A. The New Year: Meeting Friends

题目连接:

http://codeforces.com/contest/723/problem/A

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.

Sample Input

7 1 4

Sample Output

6

Hint

题意

给你三个点,你需要找到另外一个点,使得那三个点到达那个点的距离和最小。

题解:

数据范围很小,直接暴力枚举就好了。

虽然答案显然就是中间那个点的位置。

代码

#include<bits/stdc++.h>
using namespace std; int main()
{
long long x1,x2,x3;
long long ans = 1e9;
cin>>x1>>x2>>x3;
for(int i=-10000;i<=10000;i++)
{
ans = min(ans,abs(x1-i)+abs(x2-i)+abs(x3-i));
}
cout<<ans<<endl;
}

Codeforces Round #375 (Div. 2) A. The New Year: Meeting Friends 水题的更多相关文章

  1. Codeforces Round &num;356 &lpar;Div&period; 2&rpar;B&period; Bear and Finding Criminals(水题)

    B. Bear and Finding Criminals time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

  2. Codeforces Round &num;343 &lpar;Div&period; 2&rpar; A&period; Far Relative’s Birthday Cake 水题

    A. Far Relative's Birthday Cake 题目连接: http://www.codeforces.com/contest/629/problem/A Description Do ...

  3. Codeforces Round &num;385 &lpar;Div&period; 2&rpar; A&period; Hongcow Learns the Cyclic Shift 水题

    A. Hongcow Learns the Cyclic Shift 题目连接: http://codeforces.com/contest/745/problem/A Description Hon ...

  4. Codeforces Round &num;396 &lpar;Div&period; 2&rpar; A&period; Mahmoud and Longest Uncommon Subsequence 水题

    A. Mahmoud and Longest Uncommon Subsequence 题目连接: http://codeforces.com/contest/766/problem/A Descri ...

  5. Codeforces Round &num;258 &lpar;Div&period; 2&rpar; C&period; Predict Outcome of the Game 水题

    C. Predict Outcome of the Game 题目连接: http://codeforces.com/contest/451/problem/C Description There a ...

  6. Codeforces Round &num;359 &lpar;Div&period; 2&rpar; B&period; Little Robber Girl&&num;39&semi;s Zoo 水题

    B. Little Robber Girl's Zoo 题目连接: http://www.codeforces.com/contest/686/problem/B Description Little ...

  7. Codeforces Round &num;358 &lpar;Div&period; 2&rpar; B&period; Alyona and Mex 水题

    B. Alyona and Mex 题目连接: http://www.codeforces.com/contest/682/problem/B Description Someone gave Aly ...

  8. 【打CF,学算法——二星级】Codeforces Round &num;313 &lpar;Div&period; 2&rpar; B&period; Gerald is into Art(水题)

    [CF简单介绍] 提交链接:http://codeforces.com/contest/560/problem/B 题面: B. Gerald is into Art time limit per t ...

  9. Codeforces Round &num;294 &lpar;Div&period; 2&rpar;A - A and B and Chess 水题

    A. A and B and Chess time limit per test 1 second memory limit per test 256 megabytes input standard ...

随机推荐

  1. 深入理解numpy

    一.为啥需要numpy python虽然说注重优雅简洁,但它终究是需要考虑效率的.别说运行速度不是瓶颈,在科学计算中运行速度就是瓶颈. python的列表,跟java一样,其实只是一维列表.一维列表相 ...

  2. ROS语音交互(四)接入图灵语义理解

    首先程序中会用到Json,curl 安装相应的库 $ sudo apt-get install libcurl3 libcurl4-openssl-dev$ sudo apt-get install ...

  3. 特别实用而且功能强大的attributedText属性

    UILabel *sendNameLB = [[UILabel alloc]initWithFrame:CGRectMake(, , , )]; NSString * string = @" ...

  4. VS10x CodeMap 注册码 key VS插件CodeMap

    VS10x CodeMap 注册码(key): #$aCN/L/ra73OaqCJENXc2JIDL61IMawNWBBX+PxhBzobE9w3QlcrwoXeB3DWBC2f56y9r0Hx2XP ...

  5. Neutron网络性能测试与分析(一) CVR

    测试环境:网络节点运行在Intel(R) Xeon(R) CPU E5-2630 v3服务器上,网卡使用intel的万兆卡82599ES 测试仪使用本人基于dpdk编写的程序,基本上可以打满万兆卡,小 ...

  6. Java 8中Stream API学习笔记

    1)函数式编程的优势和劣势分别是什么?优势:①不可变性 ②并行操作 ③执行顺序更灵活 ④代码更加简洁纯粹的函数式编程,变量具有不可变性,同一个参数不会在不同场景下得出不同的结果,因此大大增强了系统的稳 ...

  7. java FileUtil工具类

    网上的版本太多,整合了一下适合自己用的工具类,包括读取.保存.拷贝文件等. public class FileUtil { /** * 私有构造方法,防止类的实例化,因为工具类不需要实例化. */ p ...

  8. &lbrack;C&num;&rsqb;SQL Server Express LocalDb&lpar;SqlLocalDb&rpar;的一些体会

    真觉得自己的知识面还是比较窄,在此之前,居然还不知道SqlLocalDb. SqlLocalDb是啥?其实就是简化SQL Server的本地数据库,可以这样子说,SQL Server既可以作为远程,也 ...

  9. java调试与排错

    参考网址:http://www.doc88.com/p-461115156632.html 一.Java程序调试与错误收集 1.Web程序的调试与排错:尽量使用System.out.println() ...

  10. Day 08 文件操作模式,文件复制,游标

    with open:将文件的释放交给with管理 with open('文件', '模式', encoding='utf-8') as f:    # 操作    pass​ a模式:追加写入 # t ...