CodeForces 405BDomino Effect

题目衔接:http://codeforces.com/problemset/problem/405/B

B. Domino Effect

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 with the 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 sof 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.

Examples

input

Copy

14
.L.R...LR..L..

output

Copy

4

input

Copy

5
R....

output

Copy

0

input

Copy

1
.

output

Copy

1

Note

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之间如果牌的个数是偶数就没有一张牌是站着的,如果中间牌数是奇数,则存在一张站着的牌,还要特判全部是站着的,特判L在最左边右边全是站着的牌,还有最右边是R左边全是站着的牌,然后就可以轻松水掉这题了,,,比赛的时候心态爆炸题都没看进去。。。。心态很重要啊!!

代码:


/*

*/
#include<map>
#include<set>
#include <vector>
#include<stack>
#include<queue>
#include<cmath>
#include<string>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll unsigned long long
#define inf 0x3f3f3f
#define esp 1e-8
#define bug {printf("mmp\n");}
#define mm(a,b) memset(a,b,sizeof(a))
#define T() int test,q=1;scanf("%d",&test); while(test--)
const int maxn=1e4+10;
const double pi=acos(-1.0);
const int N=201;
const int mod=1e9+7;
char s[maxn];
int book[maxn];

int main()
{
    int n;
    scanf("%d",&n);
    scanf("%s",s);
    int judge=0;///判断是否只有.
    int ans=0;///统计R-L之间有多少个.奇数加一,偶数为0
    for(int i=0; i<n; i++)
    {
        if(s[i]=='R')
        {
            judge=1;
            int cnt=0;
            for(int j=i; j<n; j++)
            {
                if(j==n-1&&s[j]=='.')
                {
                    cnt=0;
                    break;
                }
                else if(s[j]=='L')
                {
                    break;
                }
                else if(s[j]=='.')
                {
                    cnt++;
                }
            }
            if(cnt%2==1)
                ans++;
        }
    }
    ///统计L-R或结尾之间有多少个.
    for(int i=0; i<n; i++)
    {
        if(s[i]=='L')
        {
            judge=1;
            int cnt=0;
            for(int j=i; j<n; j++)
            {
                if(s[j]=='.'&&j==n-1)
                {
                    cnt++;
                    break;
                }
               else if(s[j]=='R')
                {
                    break;
                }
                else if(s[j]=='.')
                    cnt++;
            }
            ans+=cnt;
        }
    }
    ///统计R的左边.的个数
    for(int i=0; i<n; i++)
    {
        if(s[i]=='R')
        {
            judge=1;
            int cnt=0,flag=0;///统计.的个数以及判断是否出现L出现1不予考虑本次循环
            for(int j=i; j>=0; j--)
            {
                if(s[j]=='L')
                {
                    flag=1;
                    break;
                }
                else if(s[j]=='.')
                {
                    cnt++;
                }
            }
            if(!flag)
                ans+=cnt;
        }
    }
    if(!judge)
    {
        ans+=n;
    }
    printf("%d\n",ans);
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值