Codeforces Round #363 (Div. 2) A. Launch of Collider
2016-07-28 09:55
429 查看
A. Launch of Collider
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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.
Input
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.
Output
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.
Examples
input
4
RLRL
2 4 6 10
output
1
input
3
LLR
40 50 60
output
-1
Note
In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 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.
题意:给你n个点的位置和移动方向,问多久之后会有点所处位置相同。
思路:直接判断相邻点方向是否相同,然后距离/2取最小值。
ac代码:
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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.
Input
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.
Output
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.
Examples
input
4
RLRL
2 4 6 10
output
1
input
3
LLR
40 50 60
output
-1
Note
In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 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.
题意:给你n个点的位置和移动方向,问多久之后会有点所处位置相同。
思路:直接判断相邻点方向是否相同,然后距离/2取最小值。
ac代码:
#include<stdio.h> #include<math.h> #include<string.h> #include<stack> #include<set> #include<queue> #include<vector> #include<iostream> #include<algorithm> #define MAXN 1010000 #define LL long long #define ll __int64 #define INF 0x7fffffff #define mem(x) memset(x,0,sizeof(x)) #define PI acos(-1) #define eps 1e-8 using namespace std; ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} ll lcm(ll a,ll b){return a/gcd(a,b)*b;} ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;} double dpow(double a,ll b){double ans=1.0;while(b){if(b%2)ans=ans*a;a=a*a;b/=2;}return ans;} //head char s[MAXN]; int a[MAXN]; int main(){ int n;scanf("%d",&n); scanf("%s",s); for(int i=0;i<n;i++) scanf("%d",&a[i]); int cnt=INF;int bz=0; for(int i=1;i<n;i++){ if(s[i]=='L'){ if(s[i-1]=='R'){ bz=1,cnt=min(cnt,abs(a[i]-a[i-1])/2); } } } if(bz) printf("%d\n",cnt); else printf("-1\n"); return 0; }
相关文章推荐
- Linux kernel的 Makefile和Kconfig以及Make menuconfig的关系
- 【HDU5739 2016 Multi-University Training Contest 2F】【cdq分治+并查集做法 or 点双连通做法】Fantasia 每点删除后联通块权值和的积
- Java Web学习(23): JSTL学习(一)
- 校内ACM上出现Presentation Error的一点认识
- 数独
- poj 2388 堆排序
- Spring4笔记----使用外部属性文件配置 bean
- JS 中document.URL 和 windows.location.href 的区别
- IPv4与IPv6数据报格式详解
- SQL Server 存储过程遇到“表 '#TT' 没有标识属性。无法执行 SET 操作”错误
- JavaScript中的上溢、下溢和被零整除
- Java技巧--修改Eclipse默认Workspace路径
- Redis简介
- JAVA二进制.位运算.移位运算
- TCP协议的连接机制---三次握手信号的原理
- java中判断字符串是否为数字的方法的几种方法
- 关于文件 atime mtime gtime 专题
- [HDU 5754] Life Winner Bo (有平局的博弈+威佐夫博弈)
- php判断手机浏览还是web浏览,并执行相应的动作简单实例
- Spring4笔记----bean的作用范围