【模拟】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 /* 题意:给一组公式,一组数据,计算得到一系列的坐标点,画出折线图:) 模拟题:蛮恶心的,不过也简单 ...
随机推荐
- Rouh set 入门知识2(基础定义篇)
接上一篇,简单说明一下知识库的关系,设K1=(U,S1)和K2=(U,S2)为知识库 1.如果IND(S1)=IND(S2),即U/IND(S1)=U/IND(S2),则知识库K1与知识库K2是等价的 ...
- Axiom3D学习日记 2.介绍SceneManager,SceneNode,Entity
SceneManager(场景管理类) 所有出现在屏幕里的东西都受SceneManager管理(最好是这样),当你放置对象在场景里,SceneManager就会跟踪他们的位置,当你为场景创建一个相机, ...
- appium系列教程(转载)
1.系列文章:转载来源:乙醇的cnblog http://www.kuqin.com/shuoit/20140704/340994.html 2.环境部署:http://www.51testing.c ...
- xargs rm -rf 与 -exec rm
# find ./ -exec rm {} \; # find ./ | xargs rm -rf 两者都可以把find命令查找到的结果删除,其区别简单的说是前者是把find发现的结果一次性传给exe ...
- oracle-绑定变量学习笔记(未完待续)
--定义变量SQL> var a number; --给绑定变量赋值SQL> exec :a :=123; PL/SQL procedure successfully completed. ...
- NSCondition的用法,NSCondication实现线程同步,生产者消费问题实现(转载)
NSCondition的用法 使用NSCondition,实现多线程的同步,即,可实现生产者消费者问题. 基本思路是,首先要创建公用的NSCondition实例.然后: 消费者取得锁,取产品,如果没有 ...
- 在WinForm应用程序中,使用选项卡控件来加载不同的Form界面!
TabPage tp=new TabPage(); your选项卡控件.Controls.Add(tp); From1 frm=new Form1(); frm.TopLevel = false; f ...
- Python:运算符
#!/usr/bin/python3 #运算符 #算术运算符 print("算术运算符:","+ - * / % **(幂) //(取整)") #比较运算符 p ...
- js基础 - 兼容代码
js基础 - 兼容代码 . scrollTop . chrome document.body.scrollTop . IE && firefox document.documentEl ...
- wdcp-apache配置错误导致进程淤积进而内存吃紧
内存总是越来越少,虚拟内存使用越来越多 首先确定到底是什么占用了大量的内存 可以看到,大部分内存被闲置的httpd进程占用 且当我重启mysql服务后,内存没有出现明显变化,但是当我重启apache时 ...