CF699A Launch of Collider 题解
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 题解的更多相关文章
- 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 ...
- 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 ...
- codeforces #363a Launch of Collider
A. Launch of Collider time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- 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 ...
- 【CodeForces 699A】Launch of Collider
维护最新的R,遇到L时如果R出现过就更新答案. #include <cstdio> #include <algorithm> using namespace std; int ...
- 【模拟】Codeforces 699A Launch of Collider
题目链接: http://codeforces.com/problemset/problem/699/A 题目大意: 给N个点,向左或向右运动,速度均为1,问最早什么时候有两个点相撞.无解输出-1 题 ...
- CodeForces 699A Launch of Collider
枚举相邻两个$a[i]$与$a[i+1]$,如果$s[i]=R$并且$s[i+1]=L$,那么$i$和$i+1$会碰撞,更新答案. #pragma comment(linker, "/STA ...
- Codeforces Round #363 Div.2[111110]
好久没做手生了,不然前四道都是能A的,当然,正常发挥也是菜. A:Launch of Collider 题意:20万个点排在一条直线上,其坐标均为偶数.从某一时刻开始向左或向右运动,速度为每秒1个单位 ...
- Codeforces 699
Problem A Launch of Collider 题目大意 在x轴上有n个点,坐标均为偶数.每个点或向左移动或向右移动,每秒移动距离为1. 使所有点同时开始移动,求最早有点相遇的时间或无解. ...
随机推荐
- C#动态创建接口的实现实例对象
本文简单介绍如何动态创建接口interface的实现实例对象,包含两个知识点: 1.如何获取接口interface的所有实现实例对象? 2.如何判断实例对象的构造函数是否有参数? 准备工作 首先新建一 ...
- Java LinkedList小记
1. 基本用法 LinkedList实现了List.Deque.Queue接口,可以按照队列.栈和双端队列的方式进行操作.LinkedList有两个构造方法,一个是默认构造,另一个接受Collecti ...
- 力扣 - 剑指 Offer 42. 连续子数组的最大和
题目 剑指 Offer 42. 连续子数组的最大和 思路1(分析数组的规律) 我们可以从头到尾逐个累加,若之前的累加和小于0,那就从丢弃之前的累加,从当前开始重新累加,同时在遍历过程中比较记录下最大值 ...
- 快速入门上手JavaScript中的Promise
当我还是一个小白的时候,我翻了很多关于Promise介绍的文档,我一直没能理解所谓解决异步操作的痛点是什么意思 直到我翻了谷歌第一页的所有中文文档我才有所顿悟,其实从他的英文字面意思理解最为简单粗暴 ...
- 洛谷 P4564 [CTSC2018]假面(期望+dp)
题目传送门 题意: 有 \(n\) 个怪物,第 \(i\) 个怪物初始血量为 \(m_i\).有 \(Q\) 次操作: 0 x u v,有 \(p=\frac{u}{v}\) 的概率令 \(m_x\) ...
- Codeforces 1129D - Isolation(分块优化 dp)
Codeforces 题目传送门 & 洛谷题目传送门 又独立切了道 *2900( 首先考虑 \(dp\),\(dp_i\) 表示以 \(i\) 为结尾的划分的方式,那么显然有转移 \(dp_i ...
- C#集合Dictionary中按值的排序
C#集合Dictionary中按值的降序排列 static void Main(string[] args) { Dictionary<string, int> d ...
- X-MagicBox-820的luatOS之路连载系列6
继上次用Qt实现了显示地图和MQTT通信之后(X-MagicBox-820的luatOS之路连载系列5),说是要研究下地图的开放接口,也看了标记点和线的方法(地图上自定义标记点和轨迹线的实现).这次就 ...
- (数据科学学习手札132)Python+Fabric实现远程服务器连接
本文示例代码及文件已上传至我的Github仓库https://github.com/CNFeffery/DataScienceStudyNotes 1 简介 日常工作中经常需要通过SSH连接到多台远程 ...
- MapReduce03 框架原理InputFormat数据输入
目录 1 InputFormat数据输入 1.1 切片与MapTask并行度决定机制 问题引出 MapTask并行度决定机制 Job提交流程源码 切片源码 1.2 FileInputFormat切片机 ...