Codeforces 1285A Mezo Playing Zoma (思维题)

传送门

题意:

给一个长度为n的字符串,字符串只有L,R组成,L代表向左移动一个单位,R代表向右移动一个单位,但是由于某些问题,有些字符命令不执行,即遇到L可能不向左移动,遇到R可能不向右移动(不移动就是待在原地不动),最初机器人在0,问它可能移动到点的数量

思路:

直接找到最左端能移动到哪个位置,最右端能移动到哪个位置,相加再加1(原来的0位置)即可,代码很简单

代码:

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <vector>
#include <math.h>
#include <map>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
const int mod=998244353;
const int MAXN=2e5+50;
const double pi=3.1415926536;
char ch[MAXN];
int main()
{
    //freopen("in.txt","r",stdin);
    int l=0,r=0;int n;
    scanf("%d %s",&n,ch);
    for(int i=0;i<n;i++){
        if(ch[i]=='L')l++;
        else r++;
    }
    printf("%d\n",l+r+1);
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/zzl-dreamfly/p/12228807.html
今日推荐