cf#238

原创 2015年11月17日 20:52:55

Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play withthe dominoes and make a "domino show".

Chris arranges n dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the dominoes either to the left or to the right. However, somewhere between every two dominoes pushed in the same direction there is at least one domino pushed in the opposite direction.

After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right. When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces. The figure shows one possible example of the process.

Given the initial directions Chris has pushed the dominoes, find the number of the dominoes left standing vertically at the end of the process!

Input

The first line contains a single integer n (1 ≤ n ≤ 3000), the number of the dominoes in the line. The next line contains a character string s of length n. The i-th character of the string si is equal to

  • "L", if the i-th domino has been pushed to the left;
  • "R", if the i-th domino has been pushed to the right;
  • ".", if the i-th domino has not been pushed.

It is guaranteed that if si = sj = "L" and i < j, then there exists such k that i < k < j and sk = "R"; if si = sj = "R" and i < j, then there exists such k that i < k < j and sk = "L".

Output

Output a single integer, the number of the dominoes that remain vertical at the end of the process.

Sample Input

Input
14
.L.R...LR..L..
Output
4
Input
5
R....
Output
0
Input
1
.
Output
1

Hint

The first example case is shown on the figure. The four pieces that remain standing vertically are highlighted with orange.

In the second example case, all pieces fall down since the first piece topples all the other pieces.

In the last example case, a single piece has not been pushed in either direction.


其实 就那么几种情况,当前是L的话,前方有R,且两者之间数量距离为奇数,才会有一个最终站立,其余情况都倒,如果当前为R,那么前方为L,则两者之间的都不倒,如果前面没有LR,则前面都不倒,如果结束后,前方为L,L后面的都不倒,就这几种情况,用一个结构体,记录上一次信息就OK了;



#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <string.h>
#include <queue>
#include <set>
#include <vector>
#include <math.h>
using namespace std;
struct ac
{
    int dex;
    char dir;
};
char str[3005];
int main()
{
    int n,ans;
    cin>>n>>str;
    ac last;
    last.dir='.';
    last.dex=0;
    ans=0;
    for(int i=0;i<n;i++)
    {
        if(str[i]=='L')
        {
            if(last.dir=='R')
            {
                ans+=(i-last.dex-1)%2;
            }
            last.dex=i;
            last.dir='L';
        }
       else if(str[i]=='R')
       {
           if(last.dir=='L')
           {
               ans+=(i-last.dex-1);
           }
           if(last.dir=='.')
           {
               ans+=i;
           }
           last.dir='R';
           last.dex=i;
       }
       else if(i==n-1)
       {
           if(last.dir=='L')
            ans+=(i-last.dex);

       }
    }
    if(last.dir=='.')
        ans=n;
    cout<<ans<<endl;


    return 0;
}



版权声明:本文为博主原创文章,转载注明出处。

CF238_DIV1_C

题意是给一个无重边无自环的连通无向图,每次取出两条有公共点的边,求一种取边方案。无解时输出no solution。 很容易想,无解等价于边数为奇数。有解的时候靠构造。构造是一个猜想+调整的过程。 ...

cf238

C. Unusual Product 本题 (1)首先2进制运算,结果只为0或1 (2)最后的结果为所有aij*apq的和的形式 (3)对于aij,若i==j,即为对角线时,出现1次,若i!=j时,出...
  • guognib
  • guognib
  • 2014年03月23日 16:23
  • 846

CF 238E Meeting Her

最短路+搜索本题考察搜索的奇技淫巧,让我口胡一下先floyd把最短路跑出来。维护an[i]表示在i处且不在任何车上,到b的最少次数,那么最终答案是an[a]。正推无法更新答案,因为可能出现循环更新,我...

CF 238D Tape Programming

链表+模拟VFK题解:应该能注意到这个编程语言有特殊性质即指针的移动是连续的,这意味着假设我们在开头处放置足够多的“>”,那么单独取一个区间出来执行时的程序一定是完整地执行整个代码的程序的一部分。于是...

CF238_DIV1_D

题意:每次求和当前点连线斜率最大的点,然后求最小公共祖先。 对于当前点i,记和i点连线斜率最大的点为r[i],则r[i]一定是i+1或者i+1的祖先。于是预处理出r[]数组然后建树求LCA #in...

74HC238 datasheet

  • 2015年09月21日 10:04
  • 48KB
  • 下载

EM238 称重库文件

  • 2013年07月10日 14:47
  • 2KB
  • 下载

【GOF23设计模式】_桥接模式_多层继承结构JAVA238

来源:http://www.bjsxt.com/ 一、S03E238_01【GOF23设计模式】_桥接模式、多层继承结构、银行日志管理、管理系统消息管理、人力资源的奖金计算 未用桥接模式:pack...

SYSTEM 238C 安装手册

  • 2010年06月30日 12:50
  • 229KB
  • 下载

M238_CHF100A_MODBUS

  • 2012年07月07日 18:46
  • 18.5MB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:cf#238
举报原因:
原因补充:

(最多只允许输入30个字)