codeforces405B

就是简单的模拟题

康复如此的痛苦


sol:

从左往右扫

如果遇到L则清空前面的,遇到R就扫到L在结算

#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
    ll s=0; bool f=0; char ch=' ';
    while(!isdigit(ch))    {f|=(ch=='-'); ch=getchar();}
    while(isdigit(ch)) {s=(s<<3)+(s<<1)+(ch^48); ch=getchar();}
    return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
    if(x<0) {putchar('-'); x=-x;}
    if(x<10) {putchar(x+'0'); return;}
    write(x/10); putchar((x%10)+'0');
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const ll N=3005;
int n;
char a[N];
int main()
{
    int i,j,wwx=0,lwj=0,oo;
    bool flg;
    n=read(); scanf("%s",a+1);
    for(i=1;i<=n;i++)
    {
        if(a[i]=='.') wwx++;
        else if(a[i]=='L') wwx=0;
        else
        {
            lwj+=wwx; wwx=0;
            oo=0; flg=0;
            for(j=i+1;j<=n;j++)
            {
                if(a[j]=='L')
                {
                    if(oo%2==1)    lwj++;
                    i=j;
                    flg=1;
                    break;
                }
                else oo++;
            }
            if(!flg) i=n;
        }
    }
    lwj+=wwx;
    Wl(lwj);
    return 0;
}
View Code

 

posted @ 2021-10-09 23:02  yccdu  阅读(7)  评论(0编辑  收藏  举报