关闭

cf#238

146人阅读 评论(0) 收藏 举报
分类:

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;
}



1
0

猜你在找
【直播】机器学习&数据挖掘7周实训--韦玮
【套餐】系统集成项目管理工程师顺利通关--徐朋
【直播】3小时掌握Docker最佳实战-徐西宁
【套餐】机器学习系列套餐(算法+实战)--唐宇迪
【直播】计算机视觉原理及实战--屈教授
【套餐】微信订阅号+服务号Java版 v2.0--翟东平
【直播】机器学习之矩阵--黄博士
【套餐】微信订阅号+服务号Java版 v2.0--翟东平
【直播】机器学习之凸优化--马博士
【套餐】Javascript 设计模式实战--曾亮
查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:50435次
    • 积分:3165
    • 等级:
    • 排名:第10859名
    • 原创:269篇
    • 转载:16篇
    • 译文:0篇
    • 评论:8条
    博客专栏
    AC

    文章:6篇

    阅读:3629
    最新评论