Codeforces Round #375 (Div. 2) A. The New Year: Meeting Friends 水题
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 水题的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 【打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 ...
- 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 ...
随机推荐
- javascript完美拖拽的实现
直接上代码: HTML代码: <!DOCTYPE HTML> <html lang="en-US"> <head> <meta chars ...
- 线性筛的同时得到欧拉函数 (KuangBin板子)
线性筛的思想:每个被筛的数是通过它最小的质因子所筛去的. 这种思想保证了每个数只会被筛一次,从而达到线性.并且,这个思想实现起来非常巧妙(见代码注释)! 因为线性筛的操作中用到了倍数的关系去实现,因此 ...
- Android 中关于 【Cursor】 类的介绍
转自(http://www.cnblogs.com/TerryBlog/archive/2010/07/05/1771459.html) 使用过 SQLite 数据库的童鞋对 Cursor 应该不陌生 ...
- 浅介HTML DOM
什么是DOM? DOM是Document Object Model(文档对象模型)的缩写. DOM是W3C(万维网联盟)的标准. DOM定义了访问HTML和XML文档的标准: “W3C文档对象模型(D ...
- Gitlab & Github
windwos上Git的使用 软件下载地址:https://github.com/git-for-windows/git/releases/download/v2.15.1.windows.2/Git ...
- System.Web.Routing入门及进阶 下篇
上面介绍的是最简单的一种定义方式.当然我们可以建立更复杂的规则.其中就包括设定规则的默认值以及设定规则的正则表达式. UrlRouting高级应用 预计效果: 当我访问/a/b.aspx时就会转到De ...
- python2.x下pip install mysql-python报错解决办法
在https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python 下载该驱动网盘链接:https://pan.baidu.com/s/1r0fNYnU ...
- 基于bootstrap的上传插件fileinput实现ajax异步上传功能(支持多文件上传预览拖拽)
首先需要导入一些js和css文件 ? 1 2 3 4 5 6 <link href="__PUBLIC__/CSS/bootstrap.css" rel="exte ...
- read命令
read命令从键盘读取变量的值,通常用在shell脚本中与用户进行交互的场合. 该命令可以一次读取多个变量的值,变量和输入的值都需要使用空格隔开.在read命令后面,如果没有指定变量名,读取的数据将被 ...
- mysql 索引理解
数据的查询,都需要将数据从磁盘中加载到内存中进行运算加载,索引的出现,让原来每个数据块做一次IO减少为区间范围的快速定位,来减少块的io次数. 如上图,是一颗b+树,关于b+树的定义可以参见B+树,这 ...