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 #356 (Div. 2)B. 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 #343 (Div. 2) A. Far Relative’s Birthday Cake 水题

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

  3. Codeforces Round #385 (Div. 2) A. Hongcow Learns the Cyclic Shift 水题

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

  4. Codeforces Round #396 (Div. 2) A. Mahmoud and Longest Uncommon Subsequence 水题

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

  5. Codeforces Round #258 (Div. 2) C. Predict Outcome of the Game 水题

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

  6. Codeforces Round #359 (Div. 2) B. Little Robber Girl's Zoo 水题

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

  7. Codeforces Round #358 (Div. 2) B. Alyona and Mex 水题

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

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

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

  9. Codeforces Round #294 (Div. 2)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. [转载]AngularJS视图

    http://www.yiibai.com/angularjs/angularjs_views.html <html> <head> <title>Angular ...

  2. PHP使用数据库的并发问题

    在并行系统中并发问题永远不可忽视.尽管PHP语言原生没有提供多线程机制,那并不意味着所有的操作都是线程安全的.尤其是在操作诸如订单.支付等业务系统中,更需要注意操作数据库的并发问题. 接下来我通过一个 ...

  3. html之div始终停留在屏幕中间部分

    需求: 使得某一个div始终停留在屏幕中间 实现: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ...

  4. 禁止表单操作及JS控制输入的方式

    <div>表单元素特殊属性<input type="text" value="禁止输入" disabled /></div> ...

  5. iOS设置tableViewCell之间的间距(去掉UItableview headerview黏性)

    经常在项目中遇到自定义cell的情况,而且要求cell之间有间距,但是系统没有提供改变cell间距的方法,怎么办? 方法1:自定义cell的时候加一个背景View,使其距离contentView的上下 ...

  6. 第7月第11天 AVAsset

    1. An AVAsset defines the collective properties of the tracks that comprise the asset. (You can acce ...

  7. Python 入门基础10 --函数基础3 函数对象、名称空间、装饰器

    今日内容 1.函数对象 2.名称空间与作用域 3.函数的嵌套调用与闭包 4.装饰器 一.函数对象 1.1 定义 函数名存放的就是函数地址,所以函数名也就是对象,称之为函数对象 1.2 函数对象的应用 ...

  8. ecshop 2.7.x 批量测试

    下面为测试是否存在漏洞的脚本: sub MAIN($url) { use HTTP::UserAgent; my $r = HTTP::Request.new(); $r.uri: $url~'/us ...

  9. pip2和pip3冲突问题解决方法

    python使用pip安装模块时报错:unable to create process using ' '的解决方法: 参考:http://qoogle.cn/?id=39 1.删除C:\Python ...

  10. Windows运行命令

    winver---------检查Windows版本 wmimgmt.msc----打开windows管理体系结构 wupdmgr--------windows更新程序 winver--------- ...