【模拟】Codeforces 699A Launch of Collider
题目链接:
http://codeforces.com/problemset/problem/699/A
题目大意:
给N个点,向左或向右运动,速度均为1,问最早什么时候有两个点相撞。无解输出-1
题目思路:
【模拟】
模拟一下,记录往左往右的位置即可。
- //
- //by coolxxx
- ////<bits/stdc++.h>
- #include<iostream>
- #include<algorithm>
- #include<string>
- #include<iomanip>
- #include<map>
- #include<memory.h>
- #include<time.h>
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
- //#include<stdbool.h>
- #include<math.h>
- #define min(a,b) ((a)<(b)?(a):(b))
- #define max(a,b) ((a)>(b)?(a):(b))
- #define abs(a) ((a)>0?(a):(-(a)))
- #define lowbit(a) (a&(-a))
- #define sqr(a) ((a)*(a))
- #define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
- #define mem(a,b) memset(a,b,sizeof(a))
- #define eps (1e-8)
- #define J 10
- #define MAX 0x7f7f7f7f
- #define PI 3.14159265358979323
- #define N 200004
- using namespace std;
- typedef long long LL;
- int cas,cass;
- int n,m,lll,ans;
- int a[N];
- char s[N];
- int main()
- {
- #ifndef ONLINE_JUDGE
- freopen("1.txt","r",stdin);
- // freopen("2.txt","w",stdout);
- #endif
- int i,j;
- // for(scanf("%d",&cas);cas;cas--)
- // for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
- while(~scanf("%d",&n))
- // while(~scanf("%d",&n))
- {
- ans=MAX;
- scanf("%s",s+);
- for(i=;i<=n;i++)
- scanf("%d",&a[i]);
- int l=-,r=-;
- for(i=;i<=n;i++)
- {
- if(s[i]=='L')
- {
- l=a[i];
- if(r!=-)ans=min((l-r)/,ans);
- r=-;
- }
- else
- r=a[i];
- }
- if(ans==MAX)puts("-1");
- else printf("%d\n",ans);
- }
- return ;
- }
- /*
- //
- //
- */
【模拟】Codeforces 699A Launch of Collider的更多相关文章
- CodeForces 699A Launch of Collider
枚举相邻两个$a[i]$与$a[i+1]$,如果$s[i]=R$并且$s[i+1]=L$,那么$i$和$i+1$会碰撞,更新答案. #pragma comment(linker, "/STA ...
- codeforces #363a Launch of Collider
A. Launch of Collider time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- 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 ...
- 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 ...
- 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 ...
- 【CodeForces 699A】Launch of Collider
维护最新的R,遇到L时如果R出现过就更新答案. #include <cstdio> #include <algorithm> using namespace std; int ...
- 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts
题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...
- 模拟 Codeforces Round #203 (Div. 2) C. Bombs
题目地址:http://codeforces.com/problemset/problem/350/C /* 题意:机器人上下左右走路,把其他的机器人都干掉要几步,好吧我其实没读懂题目, 看着样例猜出 ...
- 模拟 Codeforces Round #249 (Div. 2) C. Cardiogram
题目地址:http://codeforces.com/contest/435/problem/C /* 题意:给一组公式,一组数据,计算得到一系列的坐标点,画出折线图:) 模拟题:蛮恶心的,不过也简单 ...
随机推荐
- inverse 相关设置
<set name="students" table = "student" inverse="true"> <!-- 指 ...
- java之log4j的配置
java之log4j的配置 log4j有很多的优点,用起来很方便,就是配置起来有些麻烦,下面我介绍一下log4j的配置方法. log4j是用来记录日志的. 软件的运行过程离不开日志.日志主要用来记录系 ...
- android 蓝牙4.0 开发介绍
最近一直在研究一个蓝牙功能 由于本人是菜鸟 学起来比较忙 一直搞了好久才弄懂 , 网上对蓝牙4.0也就是几个个dome 抄来抄去,全是英文注解 , 对英语不好的朋友来说 真是硬伤 , 一些没必要的描 ...
- Opencart 之 Registry 类详解
Registry 中文意思是记录,登记,记录本的意思, 在opencart中他的用途就是 登记公共类.类的原型放在 system\engine文件夹下 代码很简单: <?php final cl ...
- JavaScript HTML DOM - 改变 HTML
JavaScript HTML DOM - 改变 HTML HTML DOM 允许 JavaScript 改变 HTML 元素的内容. 改变 HTML 输出流 JavaScript 能够创建动态的 H ...
- CSS布局模型思考
flow模型:默认布局模型,元素从左向右.从上到下依次排列,块状元素独占一行.Position属性对应值static. float模型:主要效果是让本来独占一行的块状元素变成内联-块状元素,并到一排显 ...
- AngularJS+NodeJS环境搭建
需要安装的软件: node-v0.12.7-x64.msi python-2.7.10.amd64.msi Git-2.5.1-64-bit.exe (注意:Git安装时,需要选择的步骤) 安装位置 ...
- 利用js获取时间并输出值
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- php实现返回上一页的功能的3种有效方法
php实现返回上一页的功能的3种有效方法 header(location:你的上一页的路径); // 注意这个函数前不能有输出 header(location:.getenv("HT ...
- MySQL中删除重复数据只保留一条
用SQL语句,删除掉重复项只保留一条 在几千条记录里,存在着些相同的记录,如何能用SQL语句,删除掉重复的呢 1.查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断 SELECT ...