zoukankan      html  css  js  c++  java
  • Codeforces-699A Launch of Collider

    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个点,这n个点以每秒1m/s的速度在运动,然后给你一串字符,只包含L和R,L代表方向向左,R代表方向向右。然后给你各个点的位置,让你求最早两个点发生碰撞的时间,如果不发生碰撞为-1

    解题思路:

    暴力搞呗

    代码:

    #include <map>
    #include <set>
    #include <stack>
    #include <queue>
    #include <cstdio>
    #include <string>
    #include <vector>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    #include <functional>
    using namespace std;
    
    #define mod 7
    #define INF 0x3f3f3f3f
    #define lson (rt << 1)
    #define rson (rt << 1 | 1)
    #define Clear(a) memset(a, 0, sizeof(a))
    #define mp(a, b) make_pair((a), (b))
    #define Max(a, b) ( (a) > (b) ? (a) : (b) )
    #define Min(a, b) ( (a) < (b) ? (a) : (b) )
    
    typedef long long LL;
    typedef pair<int, int > pi;
    
    const int maxn = 2e5 + 5;
    const int dir[8][2] = {1,2, 2,1, -1,2, -2,1, 1,-2, 2,-1, -1,-2, -2,-1};
    
    int pos[maxn];
    char str[maxn];
    int main()
    {
        int n;
        scanf("%d", &n);
        scanf(" %s", str);
        for(int i = 0; i < n; ++i){
            scanf("%d", &pos[i]);
        }
        int ans = INF;
        for(int i = 0; i < n - 1; ++i){
            if(str[i] == 'R' && str[i+1] == 'L'){
                ans = min(ans, (pos[i+1] - pos[i]) / 2);
            }
        }
        printf("%d
    ", ans == INF ? -1 : ans);
        return 0;
    }


  • 相关阅读:
    Java中Date和Calender类的使用方法
    看《做性能测试需要做些什么》
    【笔记】jquery append,appendTo,prepend,prependTo 介绍
    【实践】jquery实现滑动动画及轮播
    【实践】四联联动 + 更加优化
    【实践】jQuery实现三联联动
    关于导入excel报错的处理(xls,xlsx)
    递归算法及经典案例
    验证身份证真假
    正则表达式
  • 原文地址:https://www.cnblogs.com/wiklvrain/p/8179457.html
Copyright © 2011-2022 走看看