Codeforces Round #605 (Div. 3) A. Three Friends(贪心)
链接:
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(贪心)的更多相关文章
- 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 ...
- 【cf比赛记录】Codeforces Round #605 (Div. 3)
比赛传送门 Div3真的是暴力杯,比div2还暴力吧(这不是明摆的嘛),所以对我这种一根筋的挺麻烦的,比如A题就自己没转过头来浪费了很久,后来才醒悟过来了.然后这次竟然还上分了...... A题:爆搜 ...
- Codeforces Round #605 (Div. 3)
地址:http://codeforces.com/contest/1272 A. Three Friends 仔细读题能够发现|a-b| + |a-c| + |b-c| = |R-L|*2 (其中L ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #605 (Div. 3) B. Snow Walking Robot(构造)
链接: https://codeforces.com/contest/1272/problem/B 题意: Recently you have bought a snow walking robot ...
- Codeforces Round #605 (Div. 3) 题解
Three Friends Snow Walking Robot Yet Another Broken Keyboard Remove One Element Nearest Opposite Par ...
- Codeforces Round #605 (Div. 3) E - Nearest Opposite Parity (超级源点)
随机推荐
- beanshell 通过java写数据到文件
import java.io.*; String filePath = "/data/account.txt"; String conent = vars.get("ac ...
- docker 命令(我使用过的)
是否安装docker: docker version 启动docker: service docker start 查看本机可用镜像: docker images 删除镜像: doc ...
- vue3 createComponent
这个函数不是必须的,除非你想要完美结合 TypeScript 提供的类型推断来进行项目的开发. 这个函数仅仅提供了类型推断,方便在结合 TypeScript 书写代码时,能为 setup() 中的 p ...
- HTML5中的lang属性,zh-CN还是zh-Hans?
一.资源 先提供资源.如果我弄错了什么,请以这些文档为准: W3C文档.IANA已登记的子标签.BCP 47.RFC 5646. 二.格式简介 先上一张图片: 一个Language Tags,由①到⑦ ...
- mongoDB 分组并对分组结果筛选类似于SQL中的(group by xxx having ) 附带Java代码
今天需要做一个筛选程序,因为数据放在mongodb中,没写过分组的查询语句,查了一些资料,终于写出来了,分享给各位小伙伴 需求是 查询 学员 在2019-07-29之后未同步的数据(同一个学员需要2条 ...
- deppin Linux下安装docker
首先楼主用的是deppin15.11 docker 简介:Docker作为一个软件集装箱化平台,可以让开发者构建应用程序时,将它与其依赖环境一起打包到一个容器中,然后很容易地发布和应用到任意平台中. ...
- Java多线程并发同步执行
https://www.cnblogs.com/pengdai/p/12026959.html 并发关键字:volatile,final,synchronized Collections: 并发集合 ...
- 笔记本端查看以前的wifi密码
家里老人忘记密码了.好像是我改了从,我也忘了,手中安卓手机root后也没找到记录密码的文件,水果机懒得弄了,突然想起来电脑还有记录,应该可以找到. 此篇也顺带记录下怎么通过手中笔记本找到以前练过的wi ...
- HANA- SAP S4/HANA BP屏幕增强添加自定义字段(BDT方式)
转载:https://www.cnblogs.com/hhelibeb/p/7412792.html 这里我们可以使用的技术是Business Data Toolset(以下简称BDT). 以下是网络 ...
- Solr字段类型
一.一般属性 1.name fieldType的名称.该值用于字段定义中的类型属性,强烈建议名称仅包含字母数字和下划线,不能以数字开头[非强制]. 2.class 用于存储和索引此类型数据的类名.可以 ...