链接:

https://codeforces.com/contest/1272/problem/A

题意:

outputstandard output

Three friends are going to meet each other. Initially, the first friend stays at the position x=a, the second friend stays at the position x=b and the third friend stays at the position x=c on the coordinate axis Ox.

In one minute each friend independently from other friends can change the position x by 1 to the left or by 1 to the right (i.e. set x:=x−1 or x:=x+1) or even don't change it.

Let's introduce the total pairwise distance — the sum of distances between each pair of friends. Let a′, b′ and c′ be the final positions of the first, the second and the third friend, correspondingly. Then the total pairwise distance is |a′−b′|+|a′−c′|+|b′−c′|, where |x| is the absolute value of x.

Friends are interested in the minimum total pairwise distance they can reach if they will move optimally. Each friend will move no more than once. So, more formally, they want to know the minimum total pairwise distance they can reach after one minute.

You have to answer q independent test cases.

思路:

中间的值影响不大,手动判断条件。

代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long LL; int main()
{
int t;
cin >> t;
while(t--)
{
int a[4];
for (int i = 1;i <= 3;i++)
cin >> a[i];
sort(a+1, a+4);
if (a[1] == a[2])
{
if (a[3] > a[2])
a[3]--;
if (a[1] < a[3])
a[1]++, a[2]++;
}
else if (a[2] == a[3])
{
if (a[1] < a[2])
a[1]++;
if (a[2] > a[1])
a[2]--, a[3]--;
}
else
{
a[1]++;
a[3]--;
}
int ans = a[2]-a[1]+a[3]-a[1]+a[3]-a[2];
cout << ans << endl;
} return 0;
}

Codeforces Round #605 (Div. 3) A. Three Friends(贪心)的更多相关文章

  1. Codeforces Round #605 (Div. 3) E - Nearest Opposite Parity

    题目链接:http://codeforces.com/contest/1272/problem/E 题意:给定n,给定n个数a[i],对每个数输出d[i]. 对于每个i,可以移动到i+a[i]和i-a ...

  2. 【cf比赛记录】Codeforces Round #605 (Div. 3)

    比赛传送门 Div3真的是暴力杯,比div2还暴力吧(这不是明摆的嘛),所以对我这种一根筋的挺麻烦的,比如A题就自己没转过头来浪费了很久,后来才醒悟过来了.然后这次竟然还上分了...... A题:爆搜 ...

  3. Codeforces Round #605 (Div. 3)

    地址:http://codeforces.com/contest/1272 A. Three Friends 仔细读题能够发现|a-b| + |a-c| + |b-c| = |R-L|*2 (其中L ...

  4. Codeforces Round #605 (Div. 3) E. Nearest Opposite Parity(最短路)

    链接: https://codeforces.com/contest/1272/problem/E 题意: You are given an array a consisting of n integ ...

  5. Codeforces Round #605 (Div. 3) D. Remove One Element(DP)

    链接: https://codeforces.com/contest/1272/problem/D 题意: You are given an array a consisting of n integ ...

  6. Codeforces Round #605 (Div. 3) C. Yet Another Broken Keyboard

    链接: https://codeforces.com/contest/1272/problem/C 题意: Recently, Norge found a string s=s1s2-sn consi ...

  7. Codeforces Round #605 (Div. 3) B. Snow Walking Robot(构造)

    链接: https://codeforces.com/contest/1272/problem/B 题意: Recently you have bought a snow walking robot ...

  8. Codeforces Round #605 (Div. 3) 题解

    Three Friends Snow Walking Robot Yet Another Broken Keyboard Remove One Element Nearest Opposite Par ...

  9. Codeforces Round #605 (Div. 3) E - Nearest Opposite Parity (超级源点)

随机推荐

  1. jquery+css 点赞喜欢特效

    百度盘链接 https://pan.baidu.com/s/1Nu8fiUrdffsNd6usTsUESg 密码 mps4 效果:

  2. 【基于onenet-edp的文件传输】1、调试上报数据点和端对端透传

    onenet-edp上报数据点和端对端透传 一.前言 edp是onenet用于tcp设备定制的一套协议,能够灵活地实现数据上报和透传: 二.准备工作 1.找到edp页面 进入工作台后,找到多协议接入, ...

  3. STM8L052C6T6液晶LCD驱动过程

    首先还是必要的说明,鄙人经验有限,如发现问题还请不吝赐教,反馈到邮箱mr.li.ming@qq.com 使用的液晶屏 单片机引脚 液晶的COM1-COM4分别对应单片机LCD_COM0-LCD_COM ...

  4. golang基础学习---log

    package main import ( "log" ) func init() { log.SetPrefix("TRACE: ") log.SetFlag ...

  5. js的splice和delete

    例如有一个数组是 :var textArr = ['a','b','c','d']; 这时我想删除这个数组中的b元素: 方法一:delete 删除数组 delete textArr[1]  结果为: ...

  6. 关于如何控制一个页面的Ajax读数据只读一次的简单解决办法!

    例如:一个页面有一个按钮,点击的时候用ajax去后台获取数据,获取成功以后返回.下次再点击的时候就不要去获取数据了. 解决办法有很多: 1.用Get方法去读数据,会缓存. 2.用jquery的data ...

  7. centos6安装composer

    需要使用到curl,没有的话需要 yum  -y install curl     ###安装一.下载:curl -sS https://getcomposer.org/installer | php ...

  8. GoogleMap增加标记和路线轨迹的方法

    声明:本文基于JavaScript环境编写. 前言 按照目前的项目需求,我们需要在谷歌地图上标记出当前仓库的位置.司机补货的行车路径.司机当前班次需要补货的机器的位置,同时根据补货状态的不同标记成不同 ...

  9. pandas-08 pd.cut()的功能和作用

    pandas-08 pd.cut()的功能和作用 pd.cut()的作用,有点类似给成绩设定优良中差,比如:0-59分为差,60-70分为中,71-80分为优秀等等,在pandas中,也提供了这样一个 ...

  10. 多线程:Monitor、synchronized、volatile

    Moniter的实现原理 再有人问你synchronized是什么,就把这篇文章发给他 深入理解Java中的volatile关键字 既生synchronized,何生volatile