zoukankan      html  css  js  c++  java
  • Codeforces Round #363 (Div. 2) A 暴力 水题

    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.

    题意:

    让你选出能相撞的最短时间,如果没有输出-1。

    思路:

    只有RL才能相撞,找出每一组RL,更新Min。

    作为CF首场第一道题……还是拿出来纪念一下(虽然只做出来这道TAT)

    #include <iostream>
    #include <string>
    
    using namespace std;
    
    const int maxn=200100;
    
    int n;
    int a[maxn];
    string s;
    
    int main(){
        cin>>n;
        cin>>s;
        long long Min=1e10;
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        for(int i=0;i<n-1;i++){
            if(s[i]=='R'&&s[i+1]=='L'){
                long long d=(a[i+1]-a[i])/2;
                if(d<Min)  Min=d;
            }
        }
        if(Min==1e10) cout<<-1<<endl;
        else cout<<Min<<endl;
        return 0;
    }
  • 相关阅读:
    爬虫大作业
    数据结构化与保存
    使用正则表达式,取得点击次数,函数抽离
    爬取校园新闻首页的新闻
    网络爬虫基础练习
    综合练习:词频统计
    Hadoop综合大作业
    理解MapReduce
    熟悉HBase基本操作
    熟悉常用的HBase操作
  • 原文地址:https://www.cnblogs.com/hymscott/p/5705369.html
Copyright © 2011-2022 走看看