Content

有 \(n\) 辆车在一条数轴上,第 \(i\) 辆车在 \(a_i\) 上,每辆车要么向左,要么向右。开始,它们以 \(1\) 个单位每秒的速度在行驶。问你第一次撞车发生在第几秒的时候,或者根本不会撞车。

数据范围:\(1\leqslant n\leqslant 2\times 10^5,0\leqslant x_i\leqslant x_{i+1}\leqslant 10^9\)。

Solution

我们可以很容易的发现,当且仅当相邻的两个车,左边的向右开,右边的向左开时会发生撞车。所以,枚举这样的两个车之间的距离并取最小值 \(dis\),答案就是 \(\dfrac{dis}{2}\)。

Code

#include <cstdio>
#include <algorithm>
using namespace std; char s[200007];
int n, a[200007], ans = 0x3f3f3f3f; int main() {
scanf("%d%s", &n, s + 1);
for(int i = 1; i <= n; ++i) scanf("%d", &a[i]);
for(int i = 2; i <= n; ++i)
if(s[i - 1] == 'R' && s[i] == 'L') ans = min(ans, (a[i] - a[i - 1]) / 2);
printf("%d", (ans == 0x3f3f3f3f) ? -1 : ans);
}

CF699A Launch of Collider 题解的更多相关文章

  1. A. Launch of Collider Codeforces Round #363 (Div2)

    A. Launch of Collider time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  2. Codeforces Round #363 (Div. 2)->A. Launch of Collider

    A. Launch of Collider time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  3. codeforces #363a Launch of Collider

    A. Launch of Collider time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  4. A. Launch of Collider (#363 Div.2)

    A. Launch of Collider time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  5. 【CodeForces 699A】Launch of Collider

    维护最新的R,遇到L时如果R出现过就更新答案. #include <cstdio> #include <algorithm> using namespace std; int ...

  6. 【模拟】Codeforces 699A Launch of Collider

    题目链接: http://codeforces.com/problemset/problem/699/A 题目大意: 给N个点,向左或向右运动,速度均为1,问最早什么时候有两个点相撞.无解输出-1 题 ...

  7. CodeForces 699A Launch of Collider

    枚举相邻两个$a[i]$与$a[i+1]$,如果$s[i]=R$并且$s[i+1]=L$,那么$i$和$i+1$会碰撞,更新答案. #pragma comment(linker, "/STA ...

  8. Codeforces Round #363 Div.2[111110]

    好久没做手生了,不然前四道都是能A的,当然,正常发挥也是菜. A:Launch of Collider 题意:20万个点排在一条直线上,其坐标均为偶数.从某一时刻开始向左或向右运动,速度为每秒1个单位 ...

  9. Codeforces 699

    Problem A Launch of Collider 题目大意 在x轴上有n个点,坐标均为偶数.每个点或向左移动或向右移动,每秒移动距离为1. 使所有点同时开始移动,求最早有点相遇的时间或无解. ...

随机推荐

  1. 基于IDEA Plugin插件开发,撸一个DDD脚手架

    作者:小傅哥 博客:https://bugstack.cn 沉淀.分享.成长,让自己和他人都能有所收获! 最近很感兴趣结合 IDEA Plugin 开发能力,扩展各项功能.也基于此使用不同的案例,探索 ...

  2. 8.2 k8s 基于StatefulSet运行mysql 一主多从 ,数据通过pv/pvc结合NFS服务器持久化

    1.准备mysql和xtrabackup镜像 下载mysql官方镜像并上传到本地harbor docker pull mysql:5.7 docker tag m ysql:5.7 192.168.1 ...

  3. JSOI 2008 最小生成树计数

    JSOI 2008 最小生成树计数 今天的题目终于良心一点辣 一个套路+模版题. 考虑昨天讲的那几个结论,我们有当我们只保留最小生成树中权值不超过 $ k $ 的边的时候形成的联通块是一定的. 我们可 ...

  4. 【Python小试】去除核酸特定长度的接头序列

    输入 input.txt ATTCGATTATAAGCTCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATC ATTCGATTATAAGCACTGATCGATCGATCG ...

  5. /etc/sudoers 文件

    sudo的权限控制可以在/etc/sudoers文件中查看到 如果想要控制某个用户(或某个组用户)只能执行root权限中的一部分命令, 或者允许某些用户使用sudo时不需要输入密码 格式一般都是 ro ...

  6. Redis—怎么查看Linux有没有安装Redis,如何启动Redis

    1.检测是否有安装redis-cli和redis-server [root@localhost bin]# whereis redis-cli redis-cli: /usr/bin/redis-cl ...

  7. 28-Merge Two Sorted Lists

    easy 21. Merge Two Sorted Lists Merge two sorted linked lists and return it as a new list. The new l ...

  8. lxml解析库的安装和使用

    一.lxml的安装lxml是Python的一个解析库,支持HTML和XML的解析,支持XPath解析方式,而且解析效率非常高.本节中,我们了解一下lxml的安装方式,这主要从Windows.Linux ...

  9. LetNet、Alex、VggNet分析及其pytorch实现

    简单分析一下主流的几种神经网络 LeNet LetNet作为卷积神经网络中的HelloWorld,它的结构及其的简单,1998年由LeCun提出 基本过程: 可以看到LeNet-5跟现有的conv-& ...

  10. 商业爬虫学习笔记day2

    1. get传参 (1)url中包含中文报错解决方法 urllib.request.quote("包含中文的url", safe = "string.printtable ...