codeforces C. Frog Jumps

codeforces C. Frog Jumps_第1张图片

题目

题意:

给你一个 L , R L,R L,R序列,如果青蛙在 L L L上就最多往左边跳d个格子,如果是 R R R就最多往右边跳d个格子,问青蛙跳到最右边的格子需要的最小的d是多少。

思路:

最小的距离其实就是两个 R R R之间的间隔,因为题目没说要最小次数,所以也就是说假如我们跳到了 L L L上我们就可以跳到最近的一个 R R R上面,然后由于这个R再跳到下一个R上,为了计算方便我们可以直接把首尾也设成 R R R,如果首尾只能跳到 L L L上的话,那么永远也不可能跳到尾巴。

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
typedef long long ll;
typedef vector<int> vec;
template <class T>
inline void read(T &ret) {
    char c;
    int sgn;
    if (c = getchar(), c == EOF) return ;
    while (c != '-' && (c < '0' || c > '9')) c = getchar();
    sgn = (c == '-') ? -1:1;
    ret = (c == '-') ? 0:(c - '0');
    while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
    ret *= sgn;
    return ;
}
inline void out(int x) {
    if (x > 9) out(x / 10);
    putchar(x % 10 + '0');
}
const int maxn = 2e5 + 10;
char s[maxn];
int main() {
    int t;
    read(t);
    while (t--) {
        scanf("%s", s + 1);
        int len = strlen(s + 1) + 1;
        s[0] = 'R';
        s[len] = 'R';
        int last = 0, Max = 0;
        for (int i = 0; i <= len; i++) {
            if (s[i] == 'R') Max = max(Max, i - last), last = i;
        }
        out(Max);
        putchar('\n');
    }
    return 0;
}

你可能感兴趣的:(codeforces)