链接:

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

题意:

Polycarp decided to relax on his weekend and visited to the performance of famous ropewalkers: Agafon, Boniface and Konrad.

The rope is straight and infinite in both directions. At the beginning of the performance, Agafon, Boniface and Konrad are located in positions a, b and c respectively. At the end of the performance, the distance between each pair of ropewalkers was at least d.

Ropewalkers can walk on the rope. In one second, only one ropewalker can change his position. Every ropewalker can change his position exactly by 1 (i. e. shift by 1 to the left or right direction on the rope). Agafon, Boniface and Konrad can not move at the same time (Only one of them can move at each moment). Ropewalkers can be at the same positions at the same time and can "walk past each other".

You should find the minimum duration (in seconds) of the performance. In other words, find the minimum number of seconds needed so that the distance between each pair of ropewalkers can be greater or equal to d.

Ropewalkers can walk to negative coordinates, due to the rope is infinite to both sides.

思路:

挨个计算即可

代码:

#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int maxn=2e5+7;
int main()
{
int a,b,c,d;
while(cin>>a>>b>>c>>d)
{
int result=0;
int _max=max(max(a,b),c);
int _min=min(min(a,b),c);
int _mid=a+b+c-_max-_min;
int _1=_mid-_min;
int _2=_max-_mid;
if(_1<d)
result+=(d-_1);
if(_2<d)
result+=(d-_2);
cout<<result<<endl;
}
return 0;
}

Codeforces Round #568 (Div. 2) A.Ropewalkers的更多相关文章

  1. Codeforces Round #568 (Div. 2)A

    A. Ropewalkers 题目链接:http://codeforces.com/contest/1185/problem/A 题目: Polycarp decided to relax on hi ...

  2. codeforces Round #568(Div.2)A B C

    有点菜,只写出了三道.活不多说,上题开干. A. Ropewalkers Polycarp decided to relax on his weekend and visited to the per ...

  3. Codeforces Round #568 (Div. 2)B

    B. Email from Polycarp 题目链接:http://codeforces.com/contest/1185/problem/B 题目: Methodius received an e ...

  4. Codeforces Round #568 (Div. 2) D. Extra Element

    链接: https://codeforces.com/contest/1185/problem/D 题意: A sequence a1,a2,-,ak is called an arithmetic ...

  5. Codeforces Round #568 (Div. 2) C2. Exam in BerSU (hard version)

    链接: https://codeforces.com/contest/1185/problem/C2 题意: The only difference between easy and hard ver ...

  6. Codeforces Round #568 (Div. 2) B. Email from Polycarp

    链接: https://codeforces.com/contest/1185/problem/B 题意: Methodius received an email from his friend Po ...

  7. Codeforces Round #568 (Div. 2) G1. Playlist for Polycarp (easy version) (状压dp)

    题目:http://codeforces.com/contest/1185/problem/G1 题意:给你n给选项,每个选项有个类型和价值,让你选择一个序列,价值和为m,要求连续的不能有两个相同的类 ...

  8. Codeforces Round #568 Div. 2

    没有找到这场div3被改成div2的理由. A:签到. #include<bits/stdc++.h> using namespace std; #define ll long long ...

  9. Codeforces Round #568 (Div. 2) G2. Playlist for Polycarp (hard version)

    因为不会打公式,随意就先将就一下? #include<cstdio> #include<algorithm> #include<iostream> #include ...

随机推荐

  1. Python学习之==>数组(一)

    1.定义数组 city = [] # 定义一个空数组 name = ['Jack','Panda','Bob','Franck'] # 根据下标找元素,最前面一个元素的下标是0,最后一个元素下标是-1 ...

  2. No module named 'pip'

    https://blog.csdn.net/wuyepiaoxue789/article/details/84033651 可以首先执行  python -m ensurepip  然后执行 pyth ...

  3. Day03:数组 、 继承的意义(上)

    继承 面向对象编程三(四)大特征 (抽象),封装,继承,多态什么是继承? 继承是面向对象编程中一种代码复用的方式为什么需要继承? 减少代码冗余,提高程序的可维护性和可扩展性怎样使用继承? 语法: cl ...

  4. (转)GIS中的4D产品(DLG、DRG、DEM、DOM)

    DLG 数字线划地图(DLG, Digital Line Graphic):是与现有线划基本一致的各地图要素的矢量 数据集,且保存各要素间的空间关系和相关的属性信息. 在世字测图中,最为常见的产品就是 ...

  5. 奥比中光Astra Pro在ROS系统中的使用

    奥比中光Astra Pro在ROS系统中的使用 上一次介绍了Astra Pro在ubuntu中的使用,由于Astra Pro使用uvc传输彩色图像,所以当用rqt_image_view窗口 时,看不到 ...

  6. 应用安全 - Java - 插件 - IO - excel-streaming-reader - 漏洞汇总

    xlsx-streamer.jar的XXE漏洞 Date 类型XXE 影响范围 xlsx-streamer.jar-2.0.0及以下版本 复现

  7. python基础--面向对象之绑定非绑定方法

    # 类中定义的函数分为两大类, #一,绑定方法(绑定给谁,谁来调用就自动将它本身当做第一个参数传入) # 1,绑定到类的方法:用classmethod装饰器装饰的方法. # 对象也可以掉用,仍将类作为 ...

  8. Metinfo4.0 /member/save.php 任意用户密码修改

  9. 服务器被植入木马,CPU飙升200%

    线上服务器用的是某云的,欢快的完美运行着Tomcat,MySQL,MongoDB,ActiveMQ等程序.突然一则噩耗从前线传来:网站不能访问了! 此项目是我负责,我以150+的手速立即打开了服务器, ...

  10. [codeforces#592Div2]C-G题

    题目链接 感觉这场难度迷茫,个人觉得难度排序为$A<B<D=E=G<C<F$ C题: 比赛结束1500+pp,结果出分900+fst,我就是fst的睿智Orz. 题意为给出$n ...