zoukankan      html  css  js  c++  java
  • 【模拟】Codeforces 699A Launch of Collider

    题目链接:

      http://codeforces.com/problemset/problem/699/A

    题目大意:

      给N个点,向左或向右运动,速度均为1,问最早什么时候有两个点相撞。无解输出-1

    题目思路:

      【模拟】

      模拟一下,记录往左往右的位置即可。

     1 //
     2 //by coolxxx
     3 ////<bits/stdc++.h>
     4 #include<iostream>
     5 #include<algorithm>
     6 #include<string>
     7 #include<iomanip>
     8 #include<map>
     9 #include<memory.h>
    10 #include<time.h>
    11 #include<stdio.h>
    12 #include<stdlib.h>
    13 #include<string.h>
    14 //#include<stdbool.h>
    15 #include<math.h>
    16 #define min(a,b) ((a)<(b)?(a):(b))
    17 #define max(a,b) ((a)>(b)?(a):(b))
    18 #define abs(a) ((a)>0?(a):(-(a)))
    19 #define lowbit(a) (a&(-a))
    20 #define sqr(a) ((a)*(a))
    21 #define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
    22 #define mem(a,b) memset(a,b,sizeof(a))
    23 #define eps (1e-8)
    24 #define J 10
    25 #define MAX 0x7f7f7f7f
    26 #define PI 3.14159265358979323
    27 #define N 200004
    28 using namespace std;
    29 typedef long long LL;
    30 int cas,cass;
    31 int n,m,lll,ans;
    32 int a[N];
    33 char s[N];
    34 int main()
    35 {
    36     #ifndef ONLINE_JUDGE
    37     freopen("1.txt","r",stdin);
    38 //    freopen("2.txt","w",stdout);
    39     #endif
    40     int i,j;
    41 //    for(scanf("%d",&cas);cas;cas--)
    42 //    for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
    43     while(~scanf("%d",&n))
    44 //    while(~scanf("%d",&n))
    45     {
    46         ans=MAX;
    47         scanf("%s",s+1);
    48         for(i=1;i<=n;i++)
    49             scanf("%d",&a[i]);
    50         int l=-1,r=-1;
    51         for(i=1;i<=n;i++)
    52         {
    53             if(s[i]=='L')
    54             {
    55                 l=a[i];
    56                 if(r!=-1)ans=min((l-r)/2,ans);
    57                 r=-1;
    58             }
    59             else
    60                 r=a[i];
    61         }
    62         if(ans==MAX)puts("-1");
    63         else printf("%d
    ",ans);
    64     }
    65     return 0;
    66 }
    67 /*
    68 //
    69 
    70 //
    71 */
    View Code
  • 相关阅读:
    Http record java
    Java String constructed from byte array has bad length
    Schema
    Scale-up(纵向扩展) vs Scale-out(横向扩展)
    数据同步
    JDBC and Oracle conn.commit and conn.setAutocommit not working properly
    DGIM
    Github Blog 搭建手册
    软件探索(一)
    经典书单 —— 人文社科
  • 原文地址:https://www.cnblogs.com/Coolxxx/p/5785072.html
Copyright © 2011-2022 走看看