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. java及python调用RabbitMQ

    1,python调用MQ发送消息(生产者),话不多说,直接上干货 import pika 如下图 2.java调用MQ发送消息(生产者) 具体代码如下: python 的代码如下 connection ...

  2. 【论文阅读】Beyond OCR + VQA: 将OCR融入TextVQA的执行流程中形成更鲁棒更准确的模型

    论文题目:Beyond OCR + VQA: Involving OCR into the Flow for Robust and Accurate TextVQA 论文链接:https://dl.a ...

  3. [SQL]master..sysprocesses

    --https://docs.microsoft.com/zh-cn/sql/relational-databases/system-compatibility-views/sys-sysproces ...

  4. [NOIP2017 提高组] 逛公园

    考虑先做一个\(dp\),考虑正反建图,然后按0边拓扑,然后按1到这里的最小距离排序,然后扩展这个\(f_{i,j}\),即多了\(j\)的代价的方案数.

  5. 洛谷 P5527 - [Ynoi2012] NOIP2016 人生巅峰(抽屉原理+bitset 优化背包)

    洛谷题面传送门 一道挺有意思的题,想到了某一步就很简单,想不到就很毒瘤( 首先看到这样的设问我们显然可以想到背包,具体来说题目等价于对于每个满足 \(i\in[l,r]\) 的 \(a_i\) 赋上一 ...

  6. CF1073G Yet Another LCP Problem

    题目传送门. 题意简述:给出 \(s\),多次询问给出长度分别为 \(k,l\) 的序列 \(a,b\),求 \(\sum_{i=1}^k\sum_{j=1}^l\mathrm{LCP}(s[a_i: ...

  7. Latex 文档格式化

    title: "Latex 文档格式化" author: 李龙翔 date: "Nov 22, 2019" subject: "Markdown&qu ...

  8. Excel-条件判断

    5.条件判断 IFS(条件1,真1,假1-条件2,真2,假2-条件n,真n,假n-条件n+1,...,TRUE,执行)   #可以嵌套164个(大概!具体忘了) IF(条件1,真,假)

  9. 充分利用nginx的reload功能平滑的上架和更新业务

    以前更新我们都要停服务更新,不管什么时候更新,都可能有客户在访问,体验不好,二是如果有数据传输,可能会造成数据丢失. nginx reload可以不间断更新配置文件,原理就是当我们修改配置文件发起re ...

  10. DOTA数据集

    航拍图像面临的问题 正常图像受重力作用相对固定,航拍图像的物体受拍摄角度影响 航拍图像的物体比例变化很大 某些航拍图像中小物体很密集 传统的数据集面临数据偏差的问题严重 好的数据集必备的几个特征 大量 ...