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临近 参与讨论 ...
随机推荐
- jar包后台启动--nohup篇
直接java -jar TestHttps-0.0.1-SNAPSHOT.jar的话是前段启动,但是窗口关闭之类的程序也就关闭了 我们可以nohup java -jar TestHttps-0.0.1 ...
- PXE+Kickstart 全自动安装部署CentOS7.4
一.简介 1.什么是PXE PXE(preboot execute environment,预启动执行环境)是由Intel公司开发的最新技术,工作于Client/Server的网络模式,支持工作站通过 ...
- type 命令详解
type 作用: 用来显示指定命令的类型,判断出命令是内部命令还是外部命令. 命令类型: alias: 别名 keyword:关键字, shell 保留字 function:函数, shell函数 ...
- Java 多线程笔记
资料来源于网络,仅供参考学习. 1.A Java program ends when all its threads finish (more specifically, when all its ...
- c语言中的转义序列
c中的输出函数printf()可以带以下的转义序列,不同的转义序列会得到不同的结果. 1.\a:警报 2.\b:退格(光标回退一格)3.\f:换页4.\n:换行(光标去到下一行的起始处)5.\r:回车 ...
- 类的更新----MVC设计模式
<?php class stdObject { public function __construct(array $arguments = array()) { if (!empty($arg ...
- Nginx 限制连接的实践 (DDOS)
参考: 运维人员的日常 关于限制用户连接,Nginx 提供的模块: ngx_http_limit_req_module , ngx_http_limit_conn_module , 还有 stre ...
- tornado返回指定的http code
最近做web api,需要在接口返回异常时,返回对应的http code. 查了下tornado的文档,是通过set_status方法来设置返回的http code,做个记录. self.set_st ...
- Center OS 7 安装 $$
资料来自网络,收集整理做个备忘 1. 安装Python # yum install python-setuptools && easy_install pip 2. 安装$$ # pi ...
- iOS pods-xxxx-frameworks.sh:permission denied问题
找到Build Phases, 点开Embed Pods Frameworks 是不是看到了"${SRCROOT}/Pods/Target Support Files/Pods/Pods-f ...