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\) 个单位每秒的速度在行驶.问你第一次撞车发生在第几秒的时 ...
随机推荐
- 动态规划之DP中判断是否到达某一状态(最短时间是什么)?
codevs1684 垃圾陷阱 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 卡门——农夫约翰极其珍视的一条Holste ...
- angualrjs2教程
1.一本本开源的Angular2书籍:https://zhangchen915.gitbooks.io/angular2-training/ 2.好的博客教程,讲的通俗易懂:http://codin. ...
- 导出pem证书给服务端Push Notification使用
1. 钥匙串创建Push证书的证书签名请求文件(CSR文件). 如下图所示: 2.创建App ID,创建Provisioning Profile,下载安装到XCode. 苹果开发者后台页面,创建Pus ...
- 网络采集软件核心技术剖析系列(2)---如何使用C#语言获得任意站点博文的正文及标题
一 本系列随笔概览及产生的背景 本系列开篇受到大家的热烈欢迎,这对博主是莫大的鼓励,此为本系列第二篇,希望大家继续支持,为我继续写作提供动力. 自己开发的豆约翰博客备份专家软件工具问世3年多以来,深受 ...
- mORMot访问远程数据库
mORMot访问远程数据库 mORMot中提供了TOleDBJetConnectionProperties类来处理Access的mdb数据库的访问,自带线程池.通过TSQLDBServerHttpAp ...
- 【spring data jpa】jpa中使用count计数方法
spring data jpa中使用count计数方法很简单 直接在dao层写方法即可 int countByUidAndTenementId(String parentUid, String ten ...
- python 输出所有大小写字母, range()以及列表切片
所以在写的时候,只要把它们的ASCII列出,并转化成字符型chr 即可. print [chr(i) for i in range(65,91)]#所有大写字母 print [chr(i) for i ...
- Office 2007 SP3 正试版补丁包下载
这仅仅是下载补丁包.下载地址也是微软官网的.以下是MD5是我下载后校验的. 2007 Microsoft Office 套件 Service Pack 3 (SP3) 文件名: office2007s ...
- 第十五章 MySQL 数据库
学习要点:1.Web 数据库概述2.MySQL 的操作3.MySQL 常用函数4.SQL 语句详解5.phpMyadmin 一.Web数据库概述 现在,我们已经熟悉了PHP 的基础知识,这是我们想暂时 ...
- http://blog.csdn.net/a942980741/article/details/39990699
http://blog.csdn.net/a942980741/article/details/39990699