F - Domino Effect


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

Example
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.


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

Example
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.

题意及其解题过程:如果第i个多米诺是“L”从第 i 位置一直推到左,如果第i个多米诺是“R”从第 i 位置一直推到右,如果第i个多米诺是" . "从第 i 位置尚未被推倒,同时把对应位置上的按照向左向右推倒,看最后还有几个站着。用s表示站着的个数,也就只有LL、RL、LR、RR四种情况,LL之间没有站着的;RL之间看奇偶---奇数s加1,偶数不加;LR之间有几个s就加几;RR之间没有站着的,最后输出s即可。
#include"stdio.h"
#include"string.h"
#include"stdlib.h"
#include"math.h"
#include"algorithm"
using namespace std;
char xx[3005];
struct student 
{
	int xiabiao;
	char x;
};
student a[3005];
int main()
{
	int i,j,k,n,pl,s;
	while(~scanf("%d",&n))
	{
		s=0;
		scanf("%s",xx);
		j=0;
		for(i=0;i<=n;i++)
		{
			if(xx[i]=='L'||xx[i]=='R')
			{
				a[j].x=xx[i];
				a[j].xiabiao=i;
				j++;
			}
		}
		//printf("%d\n",j);
		if(j==0)
		{
			printf("%d\n",n);
			continue;
		}
		if(a[0].x=='R')
		{
			s+=a[0].xiabiao;
		}
		//printf("a[0].x = %d\n",s);
		if(a[j-1].x=='L')
		{
			s+=n-1-a[j-1].xiabiao;
		}
		//printf("a[0].x + a[j-1].x = %d\n",s);
		for(i=0;i<j-1;i++)
		{
			if(a[i].x=='R' && a[i+1].x=='L')
			{
				k=a[i+1].xiabiao-a[i].xiabiao+1;
				if(k % 2 == 1)
				{
					s++;
				}
			}
			else if(a[i].x=='L' && a[i+1].x=='R')
			{
				k=a[i+1].xiabiao-a[i].xiabiao-1;
				s+=k;
			}
			//printf("%d\n",s);
		}
		printf("%d\n",s);
	}
	return 0;
} 


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值