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 (超级源点)
随机推荐
- [转帖]OLTP、OLAP与HTAP
OLTP.OLAP与HTAP https://blog.csdn.net/ZG_24/article/details/87854982 OLTP On-Line Transaction Proce ...
- Python之路【第二十九篇】:django ORM模型层
ORM简介 MVC或者MVC框架中包括一个重要的部分,就是ORM,它实现了数据模型与数据库的解耦,即数据模型的设计不需要依赖于特定的数据库,通过简单的配置就可以轻松更换数据库,这极大的减轻了开发人员的 ...
- Android Studio中设置与Eclipse中 Ctrl+1 功能类似的快捷键
Eclipse:Ctrl + 1 Android Studio: Alt + Enter 1. 首先当然是打开设置窗口啦,然后在IDE Settings 下找到Keymap 2. 在Keymap的搜索 ...
- KepServerEX读写三菱PLC,车间现场测试记录,带你了解【数据采集的困境】的前世与今生
1.不了解KepServerEX 的鞋童,可以先了解一下OPC UA,OPC UA服务端.我们当前项目读写三菱PLC是自己写的类库,但我感觉调用不够方便灵活,工作之余用OPC UA方式尝试一下 2.数 ...
- C#采集摄像头实时画面和抓拍
在.net中,并没有简单直接的操纵摄像头的类.那么如何简单快捷地采集摄像头的画面,进行抓拍等操作呢?答案是调用SharpCapture!专业采集摄像头画面等数据的类库.下面开始演示关键代码,您也可以在 ...
- 自学Python编程的第九天(希望有大牛帮我看看我第一个代码是否有弊端,感谢您们)----------来自苦逼的转行人
2019-09-19-22:11:33 今天是自学Python的第九天 学的内容是有关文件操作的,如:r.w.a.rb.wb.ab.r+.w+.a+等 有大牛帮我看一下我的代码第一个有没有什么弊端吗? ...
- python预习day1
计算机基础 cpu 大脑 内存 临时记忆 硬盘 永久记忆 输入设备 眼睛 耳朵 输出设备 嘴巴 操作系统 控制计算机硬件工作流程的 应用程序 安装在操作系统之上的软件 python简介 python是 ...
- Vue父子,子父,非父子组件之间传值
Vue组件基础 纯属随笔记录,具体详细教程,请查阅vue.js网站 子组件给父组件传值: <body> <div id="app"> <my-app& ...
- JS中的七大数据类型
js中有7种数据类型,包括五种基本数据类型(Number,String,Boolean,Undefined,Null),和一种复杂数据类型(Object)以及es6语法新增的Symbol数据类型 es ...
- Joomla漏洞复现
漏洞环境及利用 Joomla 3.4.6 : https://downloads.joomla.org/it/cms/joomla3/3-4-6 PHP 版本: 5.5.38 Joomla 3.4 之 ...