链接:

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. JavaScript 积累

    1. 基本类型值在内存中占据固定大小的空间,因此被保存在栈空间中: 2. 引用类型的值是对象,保存在堆空间中: 3. 从一个变量向另一个变量复制基本类型的值,会创建这个值的一个副本:从一个变量向另一个 ...

  2. Unity3D中的SendMessage使用(消息传递的三种方法)

    概述 Unity提供的消息推送机制可以非常方便我们的脚本开发,它实现的是一种伪监听者模式,利用的是反射机制. 常用函数 关于消息推送,常用的函数有三个:”SendMessage“.”SendMessa ...

  3. php连接mysql,数据CRUD操作

    插入数据 <?php $name = $_GET['username']; $sex = $_GET['sex']; $hobby = $_GET['hobby']; $address = $_ ...

  4. Yarn-本地获取任务日志

    Yarn-本地获取任务日志 yarn logs -applicationId application_1517538889175_2550 > logs.txt

  5. Element el-table-column组件列宽度设置百分比无效

    问题 使用Element table组件时,给列设置百分比宽度无效(width="30%") 解决 用属性min-width="3"代替属性width=&quo ...

  6. zabbix 监控redis python3脚本

    一:安装redis-python模块 wge  thttps://pypi.python.org/packages/source/r/redis/redis-2.9.1.tar.gz tar xf r ...

  7. JavaScript数组知识

    JavaScript数组知识 <!DOCTYPE html> <html lang="en"> <head> <meta charset= ...

  8. RabbitMQ入门教程(六):路由选择Routing

    原文:RabbitMQ入门教程(六):路由选择Routing 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog. ...

  9. MySQL数据库主从同步实战过程

       Linux系统MySQL数据库主从同步实战过程 安装环境说明 系统环境: [root@~]# cat /etc/redhat-release CentOS release 6.5 (Final) ...

  10. 深入理解JVM-垃圾回收器

    摘要: JVM垃圾回收器 看完<深入理解JVM>,结合网上资料后根据跟人理解整理出的简洁版,主要关注是什么, 怎么做到的,特点等,没有进入深入剖析,旨在快速了解,具体应用时个人再根据具体点 ...