Codefoces 723A The New Year: Meeting Friends
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.
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.
Print one integer — the minimum total distance the friends need to travel in order to meet together.
7 1 4
6
30 20 10
20
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.
题目链接:http://codeforces.com/problemset/problem/723/A
题目大意:三个人想在某个地点相遇,给出三个人在数轴上的坐标,求要走的最小值
解析:先排下序,然后另外两个人到中间人的位置为最小值(水题,自己证明),也可以最大的减最小的
代码如下:

1 #include <bits/stdc++.h>
2 using namespace std;
3 int main()
4 {
5 int a,b,c,d,s;
6 while(scanf("%d%d%d",&a,&b,&c)!=EOF)
7 {
8 if(a>=b&&b>=c)d=b;
9 else if(b>=a&&a>=c)d=a;
10 else if(a>=c&&c>=b)d=c;
11 else if(b>=c&&c>=a)d=c;
12 else if(c>=a&&a>=b)d=a;
13 else if(c>=b&&b>=a)d=b;
14 s=fabs(d-a)+fabs(d-b)+fabs(d-c);
15 printf("%d\n",s);
16 }
17 return 0;
18 }

Codefoces 723A The New Year: Meeting Friends的更多相关文章
- codeforces 723A : The New Year: Meeting Friends
Description There are three friend living on the straight line Ox in Lineland. The first friend live ...
- CodeForces 723A The New Year: Meeting Friends (水题)
题意:给定 3 个数,求其中一个数到另外两个数之间的最短距离. 析:很明显选中间那个点了. 代码如下: #pragma comment(linker, "/STACK:1024000000, ...
- 【69.77%】【codeforces 723A】The New Year: Meeting Friends
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- [LeetCode] Best Meeting Point 最佳开会地点
A group of two or more people wants to meet and minimize the total travel distance. You are given a ...
- [LeetCode] Meeting Rooms II 会议室之二
Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...
- [LeetCode] Meeting Rooms 会议室
Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...
- Scrum Meeting 20161205
本周Sprint Master 史少帅 一. 会议概要 作为一个新的sprint的开端,本次scrum meeting总结了每个人过去以来的工作,并明确了下一步的计划,具体如下: 工作总结: · 陈双 ...
- Beta阶段第十次Scrum Meeting
情况简述 BETA阶段第十次Scrum Meeting 敏捷开发起始时间 2017/1/4 00:00 敏捷开发终止时间 2017/1/5 00:00 会议基本内容摘要 deadline到来 参与讨论 ...
- Beta阶段第九次Scrum Meeting
情况简述 BETA阶段第九次Scrum Meeting 敏捷开发起始时间 2017/1/2 00:00 敏捷开发终止时间 2017/1/3 00:00 会议基本内容摘要 deadline临近 参与讨论 ...
随机推荐
- JavaScript闭包基本概念
闭包的概念 维基百科中是这么解释闭包的: 计算机科学中,闭包(也称为词法闭包或函数闭包)是指一个函数或函数的引用,与一个引用环境绑定在一起.这个函数环境是一个存储该函数每个非局部变量(也叫自由变量)的 ...
- Node之Express服务器启动安装与配置
首先安装express-generator cnpm i -g express-generator 使用express --version查看express版本 生成express服务 express ...
- 使用Node.js搭建一个本地服务器
let http = require('http'); //创建一个http let server = http.createServer((request,response)=>{ //创建一 ...
- Linux 学习记录 二 (文件的打包压缩).
前言:本文参考<鸟哥的Linux 私房菜>,如有说的不对的地方,还请指正!谢谢! 环境:Centos 6.4 和window不同,在Linux压缩文件需要注意的是,压缩后的文件会 ...
- springboot学习(三)————使用HttpMessageConverter进行http序列化和反序列化
以下内容,如有问题,烦请指出,谢谢! 对象的序列化/反序列化大家应该都比较熟悉:序列化就是将object转化为可以传输的二进制,反序列化就是将二进制转化为程序内部的对象.序列化/反序列化主要体现在程序 ...
- asp.net MVC分页
.Net MVC 分页代码,分页的关键就是在于这几个参数pageIndex ,recordCount,pageSize ,下面是张林的网站做的一个简单的分页代码 效果如图 public class ...
- php示例的错误记录
最近几天在测试php的mvc,从网上找到几个示例. 先学习这一篇,http://www.cnblogs.com/q1ng/p/4529496.html 标题是 PHP的MVC框架 深入解析,其实是最 ...
- 论文笔记-Squeeze-and-Excitation Networks
作者提出为了增强网络的表达能力,现有的工作显示了加强空间编码的作用.在这篇论文里面,作者重点关注channel上的信息,提出了"Squeeze-and-Excitation"(SE ...
- Sql Server 里的向上取整、向下取整、四舍五入取整的实例!
http://blog.csdn.net/dxnn520/article/details/8454132 =============================================== ...
- 笔记-NSArray 逆序reverseObjectEnumerator 及 NSEnumerator 遍历
//1.原始数组 NSMutableArray *array = [NSMutableArray arrayWithObjects:@"1",@"2",@&qu ...