zoukankan      html  css  js  c++  java
  • 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
    ",l+r+1);
        return 0;
    }
    
  • 相关阅读:
    模板
    2019牛客暑期多校训练营(第五场)
    Codeforces
    Codeforces
    SCUT
    模板
    Codeforces
    2019 Multi-University Training Contest 4
    Codeforces
    Codeforces
  • 原文地址:https://www.cnblogs.com/zzl_Alexander/p/12228807.html
Copyright © 2011-2022 走看看