zoukankan      html  css  js  c++  java
  • codeforces #363a Launch of Collider

    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
    #include<stdio.h>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    const int maxx = 200005;
    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=0;i<n;i++){
            scanf("%c",&p[i].dir);
        }
        for(int i=0;i<n;i++){
            scanf("%d",&p[i].pos);
        }
    
        int ans=0x7fffffff;
        for(int i=1;i<n;i++){
            if(p[i].dir!=p[i-1].dir&&p[i].dir=='L'){
                ans=min(ans,(p[i].pos-p[i-1].pos)/2);
            }
        }
        if(ans<0x7fffffff){
            printf("%d
    ",ans);
        }else{
            printf("-1");
        }
        return 0;
    }
    View Code
  • 相关阅读:
    pycharm鼠标光标变成黑色方块
    华章8月书讯,夏日静心好读书
    测试既是一门科学,也是一门艺术
    计算机科学与技术专业教指委将成立“物联网工程专业教学研究专家组”
    【七夕送好书】转微博获赠书!
    孟岩谈《C++程序设计原理与实践》
    【有奖活动】华章IT15周年,评选您心中最有影响力的10种图书
    《测试之美》连载:创建开源的QA社区
    Web前端开发之“常见模块你真的很了解吗?”
    测试驱动开发简介
  • 原文地址:https://www.cnblogs.com/superxuezhazha/p/5687393.html
Copyright © 2011-2022 走看看