Codeforces Round #568 (Div. 2) A.Ropewalkers
链接:
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的更多相关文章
- Codeforces Round #568 (Div. 2)A
A. Ropewalkers 题目链接:http://codeforces.com/contest/1185/problem/A 题目: Polycarp decided to relax on hi ...
- codeforces Round #568(Div.2)A B C
有点菜,只写出了三道.活不多说,上题开干. A. Ropewalkers Polycarp decided to relax on his weekend and visited to the per ...
- Codeforces Round #568 (Div. 2)B
B. Email from Polycarp 题目链接:http://codeforces.com/contest/1185/problem/B 题目: Methodius received an e ...
- Codeforces Round #568 (Div. 2) D. Extra Element
链接: https://codeforces.com/contest/1185/problem/D 题意: A sequence a1,a2,-,ak is called an arithmetic ...
- 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 ...
- Codeforces Round #568 (Div. 2) B. Email from Polycarp
链接: https://codeforces.com/contest/1185/problem/B 题意: Methodius received an email from his friend Po ...
- Codeforces Round #568 (Div. 2) G1. Playlist for Polycarp (easy version) (状压dp)
题目:http://codeforces.com/contest/1185/problem/G1 题意:给你n给选项,每个选项有个类型和价值,让你选择一个序列,价值和为m,要求连续的不能有两个相同的类 ...
- Codeforces Round #568 Div. 2
没有找到这场div3被改成div2的理由. A:签到. #include<bits/stdc++.h> using namespace std; #define ll long long ...
- Codeforces Round #568 (Div. 2) G2. Playlist for Polycarp (hard version)
因为不会打公式,随意就先将就一下? #include<cstdio> #include<algorithm> #include<iostream> #include ...
随机推荐
- harbor无法登陆解决
添加如下内容 [root@bogon ~]# vi /etc/docker/daemon.json { "registry-mirrors": ["https://wb2 ...
- Hibernate框架 初识 ORM概念
Hibernate概述 Hibernate是一个ORM(对象关系映射)映射框架,它的核心思想就是在底层对JDBC进行了一次封装. 什么是框架 IT语境中的框架,特指为解决一个开放性问题而设计的具有一定 ...
- VTK中,定义imread()函数,读取“.vts"文件
在本程序中,定义了一个imread()函数,用于读取“.vts”文件,第一个参数为文件路径,第二个参数为输出对象,可以输出为tkStructuredGrid型对象,也可以输出为vtkActor型对象. ...
- cosbench 安装
cosbench是什么 COSBench是Intel团队基于java开发,衡量云对象存储服务性能的基准测试工具,全称是Cloud object Storage Bench,同所有的性能测试工具一样,C ...
- Altera DDR2 IP核学习总结1-----------SRAM,DRAM
SRAM,DRAM,SDRAM和DDR2这些芯片详解网上铺天盖地的各种资料都有,这里只是根据个人习惯做一下总结,方便记忆. 详细资料可以参考https://wenku.baidu.com/view/3 ...
- 【计算机视觉】ViBe - a powerful technique for background detection and subtraction in video sequences
转自:http://blog.csdn.net/stellar0/article/details/8777283 作者:星zai ViBe算法:ViBe - a powerful technique ...
- Sqlserver2012 sa账户登录添加其他账户
1.添加admin账户的设置 2.另外 sa登录后,点击服务器名,右键->属性->安全性 的设置: 3.其次是Sqlserver配置管理器,SQL Server服务需要重启: SQL Se ...
- 反复横跳的瞄准线!从向量计算说起!基于射线检测的实现!Cocos Creator!
最近有小伙伴问我瞄准线遇到各种形状该怎么处理?如何实现反复横跳的瞄准线?最近刚好在<Cocos Creator游戏开发实战>中看到物理系统有一个射线检测,于是,基于这个射线检测,写了一个反 ...
- Centos7单机安装Tableau2018.2
cd先将服务器防火墙80级8850端口打开 临时关闭SELinux/防火墙 setenforce 0 iptables -F 重点 重点 不能用root用户安装 不能用root用户安装 第一步先创建一 ...
- MARKDOWN使用文档
ISSUE引用 引用当前项目内的ISSUE #1 markdown写法 #1 引用当前命名空间下的其他项目内的ISSUE projectname#1 sofa_ta#1 markdown写法 sofa ...