ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

CodeForces - 405B Domino Effect (模拟)

2019-04-03 10:56:24  阅读:347  来源: 互联网

标签:int Domino Effect CodeForces pushed dominoes Output domino left


Domino Effect

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

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 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 < jand 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

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

Output

4

Input

5
R....

Output

0

Input

1
.

Output

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.

题目大意:有n个多米诺骨牌,L把它往左推,R把它往右推, . 不推,问最后有几个立着的牌

代码:

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int N=3005;
char a[N];
int main()
{
    int n;
    while(~scanf("%d%s",&n,a))
    {
        int cnt=0,ans=0,k=0;
        for(int i=0; i<n; i++)
        {
            if(a[i]=='.') cnt++;
            else if(a[i]=='L') 
            {
                ans=ans+cnt+1;
                if(k==2&&cnt%2==0) ans++;
                cnt=0;
                k=1;
            }
            else if(a[i]=='R')
            {
                cnt=0;
                k=2;
            }
        }
        if(k==2) ans=ans+cnt+1;  //如果最后一个推的牌是向右推的
        printf("%d\n",n-ans);
    }
    return 0;
}

 

标签:int,Domino,Effect,CodeForces,pushed,dominoes,Output,domino,left
来源: https://blog.csdn.net/chimchim04/article/details/88989344

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有