CodeForces723-A. The New Year: Meeting Friends
1 second
256 megabytes
standard input
standard output
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.
代码1:
#include<stdio.h>
int main(){
int a,b,c,t,dis;
while(~scanf("%d %d %d",&a,&b,&c)){
if(a<b)swap(a,b);if(a<c)swap(a,c);if(b<c)swap(b,c);
dis=a-c;
printf("%d\n",dis);
}
return ;
}
代码2:
#include<stdio.h>
#include<math.h>
int main(){
int a,b,c,dis,m;
while(~scanf("%d %d %d",&a,&b,&c)){
m=;
for(int i=;i<=;i++){
dis=fabs(a-i)+fabs(b-i)+fabs(c-i);
if(m>dis)
m=dis;
}
printf("%d\n",m);
}
return ;
}
CodeForces723-A. The New Year: Meeting Friends的更多相关文章
- [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临近 参与讨论 ...
- Beta阶段第八次Scrum Meeting
情况简述 BETA阶段第八次Scrum Meeting 敏捷开发起始时间 2016/12/21 00:00 敏捷开发终止时间 2016/12/22 00:00 会议基本内容摘要 deadline临近 ...
- Beta阶段第七次Scrum Meeting
Beta阶段第七次Scrum Meeting 情况简述 BETA阶段第七次Scrum Meeting 敏捷开发起始时间 2016/12/20 00:00 敏捷开发终止时间 2016/12/21 00: ...
- Beta阶段第六次Scrum Meeting
情况简述 BETA阶段第六次Scrum Meeting 敏捷开发起始时间 2016/12/16 00:00 敏捷开发终止时间 2016/12/17 00:00 会议基本内容摘要 平稳推进 参与讨论人员 ...
- Daily Scrum Meeting 汇总
Alpha Daily Scrum Meeting --FirstDay(11.8) Daily Scrum Meeting --SecondDay(11.9) Daily Scrum Meeting ...
随机推荐
- C#中MessageBox用法大全(附效果图)
1.最简单的,只显示提示信息 2. 可以给消息框加上标题. 3. "确定"和"取消" 4. 给MessageBox加上一个Icon,.net提供常见的Icon共 ...
- bzoj 4199: [Noi2015]品酒大会
Description 一年一度的"幻影阁夏日品酒大会"隆重开幕了.大会包含品尝和趣味挑战两个环节,分别向优胜者颁发"首席品酒家"和"首席猎手&quo ...
- 【简单理解】gulp和webpack的区别
Gulp和Webpack的基本区别: gulp可以进行js,html,css,img的压缩打包,是自动化构建工具,可以将多个js文件或是css压缩成一个文件,并且可以压缩为一行,以此来减少文件体积,加 ...
- Oracle学习笔记_07_模糊查询
附录:参考资料 1.Oracle sql语言模糊查询--like后面的通配符 2.oracle sql语言模糊查询--通配符like的使用教程
- 微信小程序部署问题总结
1.微信小程序免费SSL证书Https 申请(阿里云申请) 进入阿里云控制台后,选择CA证书服务 选择购买证书 但是阿里云的免费SSL证书藏得比较深,得这样操作才能显示出免费证书 点击Symantec ...
- react看这篇就够了(react+webpack+redux+reactRouter+sass)
本帖将对一下内容进行分享: 1.webpack环境搭建: 2.如何使用react-router: 3.引入sass预编译: 4.react 性能优化方案: 5.redux结合react使用: 6.fe ...
- [SDOI2009]E&D
题目描述 小E 与小W 进行一项名为“E&D”游戏. 游戏的规则如下: 桌子上有2n 堆石子,编号为1..2n.其中,为了方便起见,我们将第2k-1 堆与第2k 堆 (1 ≤ k ≤ n)视为 ...
- MVC实现(简单小例子)
Here I’ll demonstrate simple Spring MVC framework for building web applications. First thing first. ...
- 第四章:大数据 の HBase 基础
本课主题 NoSQL 数据库介绍 HBase 基本操作 HBase 集群架构与设计介紹 HBase 与HDFS的关系 HBase 数据拆分和紧缩 引言 介绍什么是 NoSQL,NoSQL 和 RDBM ...
- [Spark内核] 第36课:TaskScheduler内幕天机解密:Spark shell案例运行日志详解、TaskScheduler和SchedulerBackend、FIFO与FAIR、Task运行时本地性算法详解等
本課主題 通过 Spark-shell 窥探程序运行时的状况 TaskScheduler 与 SchedulerBackend 之间的关系 FIFO 与 FAIR 两种调度模式彻底解密 Task 数据 ...