codeforces #363a Launch of Collider
2 seconds
256 megabytes
standard input
standard output
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. n particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, xi is the coordinate of the i-th particle and its position in the collider at the same time. All coordinates of particle positions are even integers.
You know the direction of each particle movement — it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time.
Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point.
The first line contains the positive integer n (1 ≤ n ≤ 200 000) — the number of particles.
The second line contains n symbols "L" and "R". If the i-th symbol equals "L", then the i-th particle will move to the left, otherwise the i-th symbol equals "R" and the i-th particle will move to the right.
The third line contains the sequence of pairwise distinct even integers x1, x2, ..., xn (0 ≤ xi ≤ 109) — the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order.
In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion.
Print the only integer -1, if the collision of particles doesn't happen.
4
RLRL
2 4 6 10
1
3
LLR
40 50 60
-1
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxx = ;
struct Node{
int pos;
char dir;
}p[maxx];
bool cmp(Node a,Node b){
return a.pos<b.pos;
}
int main(){
int n;
scanf("%d",&n);
getchar();
for(int i=;i<n;i++){
scanf("%c",&p[i].dir);
}
for(int i=;i<n;i++){
scanf("%d",&p[i].pos);
} int ans=0x7fffffff;
for(int i=;i<n;i++){
if(p[i].dir!=p[i-].dir&&p[i].dir=='L'){
ans=min(ans,(p[i].pos-p[i-].pos)/);
}
}
if(ans<0x7fffffff){
printf("%d\n",ans);
}else{
printf("-1");
}
return ;
}
codeforces #363a Launch of Collider的更多相关文章
- 【模拟】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)->A. 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 Codeforces Round #363 (Div2)
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 363A Soroban
模拟算盘 #include<bits/stdc++.h> using namespace std; int main() { char s[20]; scanf("%s" ...
- codeforces 363A
#include<stdio.h>//这题挺有意思小学学的算盘 int main() { int n,i,m; while(scanf("%d",&n)!=EO ...
- CF699A Launch of Collider 题解
Content 有 \(n\) 辆车在一条数轴上,第 \(i\) 辆车在 \(a_i\) 上,每辆车要么向左,要么向右.开始,它们以 \(1\) 个单位每秒的速度在行驶.问你第一次撞车发生在第几秒的时 ...
随机推荐
- virtualenvwrapper的安装及问题解决
安装virtualenvwrapperyum install python-setuptools python-develpip install virtualenvwrapper # linux下 ...
- JQuery提示$(...).on is not a function解决方法
版本太低了,引入较高的版本,如jquery-1.8.3.min.js
- ztree jquery 树 控件
插件地址:http://www.ztree.me 数据:[{"id":1,"pId":-1,"name":"根目录"}, ...
- CentOS6 安装golang
CentOS6 安装golang 下载 wget http://golangtc.com/static/go/1.8/go1.8.linux-amd64.tar.gz 1 1 1 解压 tar -xz ...
- 【转载】【Todo】Nodejs的优缺点
Nodejs的优缺点,这里面讲的比较详细.有时间可以多看看别人的分析. https://www.zhihu.com/question/19653241 Node.js 的架构与 Django, Rai ...
- 第十五章 MySQL 数据库
学习要点:1.Web 数据库概述2.MySQL 的操作3.MySQL 常用函数4.SQL 语句详解5.phpMyadmin 一.Web数据库概述 现在,我们已经熟悉了PHP 的基础知识,这是我们想暂时 ...
- PostgreSQL数据库的安装与配置
项目中要用PostgreSQL,所以专门学习了一下如何安装和调试postgresql,此博文用来记录自己的安装和调试过程,安装环境是centos7. 首先尝试了yum安装,因为毕竟yum安装简单粗暴, ...
- 使用pip安装tensorflow 0.80,python 使用tensorflow 0.80遇到的问题及处理方法
http://blog.csdn.net/levy_cui/article/details/51251095 1.python 版本切换到2.7 推荐使用pythonbrew,http://blog. ...
- 一张图片教会你写mysql 语句
MySQL的语句执行顺序 MySQL的语句一共分为11步,如下图所标注的那样,最先执行的总是FROM操作,最后执行的是LIMIT操作.其中每一个操作都会产生一张虚拟的表,这个虚拟的表作为一个处理的输入 ...
- C/C++ linux下光标定位和清屏函数
printf("\033[47;31mhello world\033[5m"); 47是字背景颜色, 31是字体的颜色, hello world是字符串. 后面的\033[5m是 ...