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 ...
随机推荐
- Dubbo学习笔记10:Dubbo服务消费方启动流程源码分析
同理我们看下服务消费端启动流程时序图: 在<Dubbo整体架构分析>一文中,我们提到服务消费方需要使用ReferenceConfig API来消费服务,具体是调用代码(1)get()方法来 ...
- Java SpringMVC框架学习(二)httpServeltRequest和Model传值的区别
HttpServletRequest 为什么大多程序在controller中给jsp传值时使用model.addAttribute()而不使用httpServeletRequest.setAttrib ...
- <header><footer>引用
示例:http://www.w3school.com.cn/html/html_layout.asp
- 运算符,比如+, -, >, <, 以及下标引用[start:end]等等,从根本上都是定义在类内部的方法。
python解释器在碰到+号运算符时,会调用加号前面的对象的__add__方法 class a: def __add__(self,b): print "ghh" aa=a() a ...
- E. Andrew and Taxi(二分+拓扑判环)
题目链接:http://codeforces.com/contest/1100/problem/E 题目大意:给你n和m,n代表有n个城市,m代表有m条边,然后m行输入三个数,起点,终点,花费.,每一 ...
- 恶意代码分析实战-确认EXE什么时候编译的
场景 确认开源的后门在中毒机器上是什么版本,具有什么功能. 思路 1.查看样本PE里的编译时间 2.对照开源后门里组件的编译时间 技术点 查看NT头-TimeDateStamp struct IMAG ...
- Ansible Tower系列 二(安装 Tower)【转】
文档:http://docs.ansible.com/ansible-tower/ 安装前检查 python版本为2.6 保持网络畅通 内存预留充足 安装用户为root 软件下载 下载地址:http: ...
- C# 将某个方法去异步执行
C# 将某个方法去异步执行 Task.Run(() => { string msgerror = SendPhoneCode.NewSendByTemplate(apply.PhoneNum, ...
- 【坐在马桶上看算法】算法7:Dijkstra最短路算法
上周我们介绍了神奇的只有五行的Floyd最短路算法,它可以方便的求得任意两点的最短路径,这称为“多源最短路”.本周来来介绍指定一个点(源点)到其余各个顶点的最短路径,也叫做“单源最短路径 ...
- JMeter出现“the target server failed to respond“的解决办法
今天用jmeter压测执行过程中遇到一个报错如下: 解决方案如下: 1. 修改执行计划中,HTTP请求的Implementation为HttpClient4. 2. 保存执行计划 3. 修改JMete ...