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临近 参与讨论 ...
随机推荐
- lua 实现tableToString
function tableToString(studentNum) local str = "{ " str = str.."\n" for k, v in ...
- CubeSuit+ ( CS+ for ca )
作为瑞萨单片机的初学者,最先接触的当属它的IDE了,接下来我将分享一些我使用这款单片机的心得,以供大家参考. 我使用的是RL78F13系列R5F10BGE,那如何建立一个能使用的工程呢?相信大家在网络 ...
- [置顶]
xamarin android自定义spinner
以前弄的一个下拉框时自带的spinner,感觉好丑,实际效果实在满足不了基本的UI界面要求,还是自己动手丰衣足食,看了网上关于android中自定义spinner的文章,感觉实现原理还是比较简单,所以 ...
- C#中级-Windows Service程序安装注意事项
一.前言 这周除了改写一些识别算法外,继续我的Socket服务编写.服务器端的Socket服务是以Windows Service的形式运行的. 在我完成Windows Service编写后,启动服务时 ...
- centOS7 jdk安装
1.查找需要卸载的OpenJDK: # rpm -qa | grep java 2:依次卸载 rpm -e --nodeps javapackages-tools-3.4.1-6.el7_0.noa ...
- uptime 命令详解
作用: 打印系统总共运行了多长时间和系统的平均负载. uptime 命令可以显示的信息依次为: 现在时间, 系统已经运行时间, 目前登录用户个数, 系统1,5,15 分钟内的平均负载 实例: up ...
- Shader 1:能接受阴影的透明shader
第一次接触Shader,项目需要,直接说需求吧,需要一个透明并且能接受阴影的shader.unity系统自带的shader已经满足不了了.上一段代码吧 Shader "GreenArch/T ...
- Dubbo(三) 安装Zookeeper 单机-集群
一.下载zookeeper zookeeper下载地址:https://www.apache.org/dyn/closer.cgi/zookeeper/点击下载 二.启动配置 选择合适版本下载后解压到 ...
- 使用HTML语言和CSS开发商业站点
第一章 预习笔记 单词: head:前进 title:标题 meta:超过 body:身体.尸体 W3C:全球最大的中文Web技术教程 strong:强烈的 target:目标,对象 href:水平参 ...
- composer安装laravel
安装composer composer是一个很有用的工具,我将用它在本机(win7)上安装laravel 到composer的官网,根据自己的系统要求下载相应的版本 安装laravel 首先cmd下进 ...