题目链接:

  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+);
  48. for(i=;i<=n;i++)
  49. scanf("%d",&a[i]);
  50. int l=-,r=-;
  51. for(i=;i<=n;i++)
  52. {
  53. if(s[i]=='L')
  54. {
  55. l=a[i];
  56. if(r!=-)ans=min((l-r)/,ans);
  57. r=-;
  58. }
  59. else
  60. r=a[i];
  61. }
  62. if(ans==MAX)puts("-1");
  63. else printf("%d\n",ans);
  64. }
  65. return ;
  66. }
  67. /*
  68. //
  69.  
  70. //
  71. */

【模拟】Codeforces 699A Launch of Collider的更多相关文章

  1. CodeForces 699A Launch of Collider

    枚举相邻两个$a[i]$与$a[i+1]$,如果$s[i]=R$并且$s[i+1]=L$,那么$i$和$i+1$会碰撞,更新答案. #pragma comment(linker, "/STA ...

  2. codeforces #363a Launch of Collider

    A. Launch of Collider time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  3. Codeforces Round #363 (Div. 2)->A. Launch of Collider

    A. Launch of Collider time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  4. A. Launch of Collider Codeforces Round #363 (Div2)

    A. Launch of Collider time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  5. A. Launch of Collider (#363 Div.2)

    A. Launch of Collider time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  6. 【CodeForces 699A】Launch of Collider

    维护最新的R,遇到L时如果R出现过就更新答案. #include <cstdio> #include <algorithm> using namespace std; int ...

  7. 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts

    题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...

  8. 模拟 Codeforces Round #203 (Div. 2) C. Bombs

    题目地址:http://codeforces.com/problemset/problem/350/C /* 题意:机器人上下左右走路,把其他的机器人都干掉要几步,好吧我其实没读懂题目, 看着样例猜出 ...

  9. 模拟 Codeforces Round #249 (Div. 2) C. Cardiogram

    题目地址:http://codeforces.com/contest/435/problem/C /* 题意:给一组公式,一组数据,计算得到一系列的坐标点,画出折线图:) 模拟题:蛮恶心的,不过也简单 ...

随机推荐

  1. inverse 相关设置

    <set name="students" table = "student" inverse="true"> <!-- 指 ...

  2. java之log4j的配置

    java之log4j的配置 log4j有很多的优点,用起来很方便,就是配置起来有些麻烦,下面我介绍一下log4j的配置方法. log4j是用来记录日志的. 软件的运行过程离不开日志.日志主要用来记录系 ...

  3. android 蓝牙4.0 开发介绍

    最近一直在研究一个蓝牙功能 由于本人是菜鸟  学起来比较忙 一直搞了好久才弄懂 , 网上对蓝牙4.0也就是几个个dome 抄来抄去,全是英文注解 , 对英语不好的朋友来说 真是硬伤 , 一些没必要的描 ...

  4. Opencart 之 Registry 类详解

    Registry 中文意思是记录,登记,记录本的意思, 在opencart中他的用途就是 登记公共类.类的原型放在 system\engine文件夹下 代码很简单: <?php final cl ...

  5. JavaScript HTML DOM - 改变 HTML

    JavaScript HTML DOM - 改变 HTML HTML DOM 允许 JavaScript 改变 HTML 元素的内容. 改变 HTML 输出流 JavaScript 能够创建动态的 H ...

  6. CSS布局模型思考

    flow模型:默认布局模型,元素从左向右.从上到下依次排列,块状元素独占一行.Position属性对应值static. float模型:主要效果是让本来独占一行的块状元素变成内联-块状元素,并到一排显 ...

  7. AngularJS+NodeJS环境搭建

    需要安装的软件: node-v0.12.7-x64.msi python-2.7.10.amd64.msi Git-2.5.1-64-bit.exe (注意:Git安装时,需要选择的步骤)  安装位置 ...

  8. 利用js获取时间并输出值

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  9. php实现返回上一页的功能的3种有效方法

    php实现返回上一页的功能的3种有效方法 header(location:你的上一页的路径);   //   注意这个函数前不能有输出 header(location:.getenv("HT ...

  10. MySQL中删除重复数据只保留一条

    用SQL语句,删除掉重复项只保留一条 在几千条记录里,存在着些相同的记录,如何能用SQL语句,删除掉重复的呢 1.查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断 SELECT ...