【Codeforces】-699A-Launch of Collider(思维)
2016-07-20 21:32
337 查看
点击打开题目
A. Launch of Collider
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
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.
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
output
input
output
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.
找到最小的相邻的一个向右一个向左的坐标相减除以二就是最短碰撞时间
A. Launch of Collider
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
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.
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.
找到最小的相邻的一个向右一个向左的坐标相减除以二就是最短碰撞时间
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; #define MAX 0x3f3f3f3f int a[200000+11]; char c[200000+11]; int main() { int n; while(~scanf("%d",&n)) { int minn=MAX; getchar; scanf("%s",c); for(int i=0;i<n;i++) scanf("%d",&a[i]); for(int i=0;i<n-1;i++) { if(c[i]=='R'&&c[i+1]=='L') //相邻最小 minn=min(minn,(a[i+1]-a[i])>>1); //更新最小 else continue; } if(minn==MAX) printf("-1\n"); else printf("%d\n",minn); } return 0; }
相关文章推荐
- UML学习
- Linux系统编程--文件(一)
- H - 不要62
- kernel32.CreateFileW boot.img
- win10镜像重装,快速设置之后无限重启怎么办?
- 使用mybatis-generator-core快速生成代码
- C语言中FILE相关与CodeBlocks命令行(windows)
- 如何将excel数据导入mongoDB数据库?
- 链式存储无向图的基本操作
- jQuery Mobile 列表视图
- 室内定位综述
- 机器学习3 logistic回归
- Chapter14~执行环境
- C语言之内存覆盖
- Android LayoutInflater详解
- 九九乘法表
- jQuery makeArray对标签或json转变成数组
- poj 2421 (最小生成树 Prime+kruskal)
- I/O流外篇之File类、简述Lambda表达式
- HIVE(1)--基础操作。