Codeforces Round #363 (Div. 2)->A. 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
In the first sample case the first explosion will happen in 1 microsecond because the particles number 1and 2 will simultaneously be at the same point with the coordinate 3.
In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point.
题意理解:有很多粒子在同一条直线上飞,速度是1,RL表示粒子的飞行方向,求粒子碰撞的最早时间,若不会碰撞就输出-1;
思路:只要是RL连着的就会碰撞,然后输出最小的minn/2;
- #include<bits/stdc++.h>
- using namespace std;
- int a[];
- int main() {
- int n;
- string s;
- cin>>n>>s;
- for(int i=; i<n; i++)
- cin>>a[i];
- int minn=-;
- for(int i=; i<n-; i++) {
- if(s[i]=='R'&&s[i+]=='L') {
- if(minn==-)
- minn=a[i+]-a[i];
- else
- minn=min(minn,a[i+]-a[i]);
- }
- }
- if(minn!=-)
- cout<<minn/<<endl;
- else
- cout<<minn<<endl;
- return ;
- }
Codeforces Round #363 (Div. 2)->A. Launch of Collider的更多相关文章
- Codeforces Round 363 Div. 1 (A,B,C,D,E,F)
Codeforces Round 363 Div. 1 题目链接:## 点击打开链接 A. Vacations (1s, 256MB) 题目大意:给定连续 \(n\) 天,每天为如下四种状态之一: 不 ...
- Codeforces Round #363 Div.2[111110]
好久没做手生了,不然前四道都是能A的,当然,正常发挥也是菜. A:Launch of Collider 题意:20万个点排在一条直线上,其坐标均为偶数.从某一时刻开始向左或向右运动,速度为每秒1个单位 ...
- Codeforces Round #363 (Div. 2) A、B、C
A. Launch of Collider time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- Codeforces Round #363 (Div. 2)
A题 http://codeforces.com/problemset/problem/699/A 非常的水,两个相向而行,且间距最小的点,搜一遍就是答案了. #include <cstdio& ...
- Codeforces Round #363 (Div. 1) B. Fix a Tree 树的拆环
题目链接:http://codeforces.com/problemset/problem/698/B题意:告诉你n个节点当前的父节点,修改最少的点的父节点使之变成一棵有根树.思路:拆环.题解:htt ...
- Codeforces Round #363 (Div. 2) A
Description There will be a launch of a new, powerful and unusual collider very soon, which located ...
- Codeforces Round #363 (Div. 2) A 水
Description There will be a launch of a new, powerful and unusual collider very soon, which located ...
- Codeforces Round #363 (Div. 2) D. Fix a Tree —— 并查集
题目链接:http://codeforces.com/contest/699/problem/D D. Fix a Tree time limit per test 2 seconds memory ...
- Codeforces Round #363 (Div. 2) B. One Bomb —— 技巧
题目链接:http://codeforces.com/contest/699/problem/B 题解: 首先统计每行每列出现'*'的次数,以及'*'出现的总次数,得到r[n]和c[m]数组,以及su ...
随机推荐
- jQuery鼠标事件
鼠标事件是在用户移动鼠标光标或者使用任意鼠标键点击时触发的. (1):click事件:click事件于用户在元素敲击鼠标左键,并在相同元素上松开左键时触发. $('p').click ...
- ApplicationContext容器的设计原理
1.在ApplicationContext容器中,我们以常用的FileSystemXmlApplicationContext的实现为例来说明ApplicationContext容器的设计原理. 2.在 ...
- 记录一下hdu的几道题
杭州电子科技大学程序设计竞赛 2016‘12-网络同步赛 前几天看到这个比赛,想着要是到时候没事就做一下,但是中午实在太困,加上水平太次,才a了4道题目. 说明:我是看ac人数多少的顺序来做题的. 1 ...
- 小米pad MI PAD 开发者选项、USB调试开启方式
设置->关于平板->在MIUI版本一行连续点击7次. 之后就出现了开发者选项.可以开启USB调试等. 你能想到吗……??
- netstat监控大量ESTABLISHED连接与Time_Wait连接问题(转载)
问题描述: 在不考虑系统负载.CPU.内存等情况下,netstat监控大量ESTABLISHED连接与Time_Wait连接. # netstat -n | awk '/^tcp/ {++y[$NF] ...
- Hadoop 的部署适用性(网上资料http://www.linuxidc.com/Linux/2013-10/92141.htm)
近些年,Hadoop和“走向大数据分析引擎”一样,受到颇多赞誉.对很多人来说,Hadoop就意味着大数据技术.但其实开源的分布式处理框架未必能解决所有的大数据问题.这就要求想要部署Hadoop的公司慎 ...
- Amazon Kinesis Producer Library 使用记录
Amazon Kinesis 是一种托管的服务,用于有弹性与扩展性的实时处理大规模的流数据.该服务收集大数据记录流,多个可在 Amazon EC2 实例上运行的数据处理应用程序随后可实时使用此流. 在 ...
- Android砖机救活(索爱MT15i)
前言 接触Android时间长了就想编译一套属于自己的系统,摘取不必要的那些组件,然后刷到手机上,俗话说的好,“常在河 边走,哪有不湿鞋”.果不其然,刷完自己编译的系统手机变砖了,具体情况为 开不开机 ...
- 开源免费的C/C++网络库(c/c++ sockets library)
(1)ACE 庞大.复杂,适合大型项目.开源.免费,不依赖第三方库,支持跨平台. http://www.cs.wustl.edu/~schmidt/ACE.html (2)Asio Asio基于Boo ...
- C# sogou地图API应用总结(二)
在地图上添加自己想要的功能模块 具体代码如下 var map; window.onload = function () { var myOptions = { mapControl: false, / ...