123
诺米骨牌模拟, 从左到右扫描,一遍, 两种状态,如果遇到L 则计数清零, 遇到R 统计.的个数
同理, 转到 从R 开始 遇到 R 清零 遇到L 计算L_R 直接的.的个数 奇数 ans+1 最后 在统计 左右边 无R的情况
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <stdlib.h>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <vector>
#define mem(a,b) memset(a,b,sizeof(a))
#define findx(x) lower_bound(b+1,b+1+bn,x)-b
#define FIN freopen("input.txt","r",stdin)
#define FOUT freopen("output.txt","w",stdout)
#define S1(n) scanf("%d",&n)
#define SL1(n) scanf("%I64d",&n)
#define SL2(n,m) scanf("%I64d%I64d",&n,&m)
#define S2(n,m) scanf("%d%d",&n,&m)
#define SS(n) scanf("%s",str)
#define Pr(n) printf("%d\n",n)
using namespace std;
typedef long long ll;
const double PI=acos(-1);
const int INF=0x3f3f3f3f;
const double esp=1e-6;
const int maxn=1e6+5;
const int MOD=1e9+7;
const int mod=1e9+7;
int dir[5][2]={0,1,0,-1,1,0,-1,0};
ll inv[maxn*2],fac[maxn];
ll gcd(ll a,ll b){ return b?gcd(b,a%b):a;}
ll exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=1;y=0;return a;}ll ans=exgcd(b,a%b,x,y);ll temp=x;x=y;y=temp-a/b*y;return ans;}
ll lcm(ll a,ll b){ return b/gcd(a,b)*a;}
ll qpow(ll x,ll n){ll res=1;for(;n;n>>=1){if(n&1)res=(res*x)%MOD;x=(x*x)%MOD;}return res;}
void INV(){inv[1] = 1;for(int i = 2; i < maxn; i++) inv[i] = (MOD - MOD / i) * inv[MOD % i] % MOD;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){ x=1; y=0; d=a; }else{ ex_gcd(b,a%b,d,y,x); y-=x*(a/b);}}
void Fac(){fac[0]=1;for(int i=1;i<=maxn;i++)fac[i]=(fac[i-1]*i)%MOD;}
ll inv_exgcd(ll a,ll n){ll d,x,y;ex_gcd(a,n,d,x,y);return d==1?(x+n)%n:-1;}
ll inv1(ll b){return b==1?1:(MOD-MOD/b)*inv1(MOD%b)%MOD;}
ll inv2(ll b){return qpow(b,MOD-2);}
ll cal(ll m,ll n){if(m<n)return 0;return (fac[m]*inv[fac[n]]%MOD)%MOD*inv[fac[m-n]]%MOD;}
ll cals(ll m,ll n){if(m<n)return 0;return (fac[m]*inv1(fac[n])%MOD)%MOD*inv1(fac[m-n])%MOD;}
char str[maxn];
int a[maxn];
int main()
{
int n;
ll ans;
while(~S1(n))
{
mem(a,0);
mem(str,0);
SS(str);
int len=strlen(str);
for(int i=0;i<len;i++)
{
if(str[i]=='.')
a[i]=0;
else if(str[i]=='L')
a[i]=1;
else
a[i]=2;
}
ans=0;
int cont=0;
int flag=0;
for(int i=0;i<len;i++)
{
if(!flag)
{
if(a[i]==0)
cont++;
if(a[i]==1)
cont=0;
if(a[i]==2)
{
ans+=cont;
cont=0;
flag=1;
}
}
else
{
if(a[i]==0)
cont++;
if(a[i]==2)
cont=0;
if(a[i]==1)
{
if(cont&1)
ans++;
cont=0;
flag=0;
}
}
}
if(!flag)
ans+=cont;
Pr(ans);
}
}