[Codeforces Round #627]1324C - Frog Jumps[思维]

1324C - Frog Jumps[思维]

time limit per testmemory limit per testinputoutput
2 seconds256 megabytesstandard inputstandard output

Description:

There is a frog staying to the left of the string s = s 1 s 2 … s n s=s_1s_2…s_n s=s1s2sn consisting of n n n characters (to be more precise, the frog initially stays at the cell 0 0 0). Each character of s is either ′ L ′ 'L' L or ′ R ′ 'R' R. It means that if the frog is staying at the i i i-th cell and the i i i-th character is ′ L ′ 'L' L, the frog can jump only to the left. If the frog is staying at the i i i-th cell and the i i i-th character is ′ R ′ 'R' R, the frog can jump only to the right. The frog can jump only to the right from the cell 0 0 0.
Note that the frog can jump into the same cell twice and can perform as many jumps as it needs.
The frog wants to reach the n + 1 n+1 n+1-th cell. The frog chooses some positive integer value d d d before the first jump (and cannot change it later) and jumps by no more than d d d cells at once. I.e. if the i i i-th character is ′ L ′ 'L' L then the frog can jump to any cell in a range [ m a x ( 0 , i − d ) , i − 1 ] [max(0,i−d), i−1] [max(0,id),i1], and if the i i i-th character is ′ R ′ 'R' R then the frog can jump to any cell in a range [ i + 1 , m i n ( n + 1 , i + d ) ] [i+1, min(n+1, i+d)] [i+1,min(n+1,i+d)].
The frog doesn’t want to jump far, so your task is to find the minimum possible value of d d d such that the frog can reach the cell n + 1 n+1 n+1 from the cell 0 0 0 if it can jump by no more than d d d cells at once. It is guaranteed that it is always possible to reach n + 1 n+1 n+1 from 0 0 0.
You have to answer t t t independent test cases.

Input

The first line of the input contains one integer t ( 1 ≤ t ≤ 1 0 4 ) t (1≤t≤10^4) t(1t104) — the number of test cases.
The next t t t lines describe test cases. The i i i-th test case is described as a string s s s consisting of at least 1 1 1 and at most 2 ⋅ 1 0 5 2⋅10^5 2105 characters ′ L ′ 'L' L and ′ R ′ 'R' R.
It is guaranteed that the sum of lengths of strings over all test cases does not exceed 2 ⋅ 1 0 5 ( ∑ ∣ s ∣ ≤ 2 ⋅ 1 0 5 ) 2⋅10^5 (\sum |s|≤2⋅10^5) 2105(s2105)

Output

For each test case, print the answer — the minimum possible value of d such that the frog can reach the cell n + 1 n+1 n+1 from the cell 0 0 0 if it jumps by no more than d d d at once.


Example input

6
LRLRRLL
L
LLR
RRRR
LLLLLL
R

Example output

3
2
3
1
7
1

Note

The picture describing the first test case of the example and one of the possible answers:
在这里插入图片描述
In the second test case of the example, the frog can only jump directly from 0 0 0 to n + 1 n+1 n+1.
In the third test case of the example, the frog can choose d = 3 d=3 d=3, jump to the cell 3 3 3 from the cell 0 0 0 and then to the cell 4 4 4 from the cell 3 3 3.
In the fourth test case of the example, the frog can choose d = 1 d=1 d=1 and jump 5 5 5 times to the right.
In the fifth test case of the example, the frog can only jump directly from 0 to n + 1 n+1 n+1.
In the sixth test case of the example, the frog can choose d = 1 d=1 d=1 and jump 2 2 2 times to the right.


分析:
题意:
给一个长度为 n n n的字符串,位置分别在 [ 1 , n ] [1,n] [1,n]
青蛙从 0 0 0开始跳,最大距离可以跳 d d d
在每个位置可以跳的方向为所在位置字符串的方向
′ L ′ 'L' L就只能往左跳, ′ R ′ 'R' R就只能往右跳
最终要达到 n + 1 n+1 n+1的位置,问最小的 d d d应该是多少
做法:
只要计算相邻的 ′ R ′ 'R' R之间的最大距离,注意 n + 1 n+1 n+1位置也要当成一个 ′ R ′ 'R' R,因为最后一定要跳到这个位置


Code:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int maxn = 2e5 + 5;
const int inf = 0x3f3f3f3f;

int read() {
    int x = 0, f = 0; char ch = getchar();
    while(ch < '0' || ch > '9') {if(ch == '-')f = -f; ch = getchar();}
    while(ch >= '0' && ch <= '9') {x = (x<<3)+(x<<1)+ch-'0'; ch = getchar();}
    return x;
}

char str[maxn];

int main() {
    int T;
    scanf("%d", &T);
    while(T--) {
        scanf("%s", str + 1);
        int len = strlen(str + 1) + 1, pre = 0, ans = 0;
        str[len] = 'R';
        for(int i = 1; i <= len; ++i) {
            if(str[i] == 'L')   continue;
            ans = max(ans, i - pre);
            pre = i;
        }
        printf("%d\n", ans);
    }
    return 0;
}




基于SSM框架的智能家政保洁预约系统,是一个旨在提高家政保洁服务预约效率和管理水平的平台。该系统通过集成现代信息技术,为家政公司、家政服务人员和消费者提供了一个便捷的在线预约和管理系统。 系统的主要功能包括: 1. **用户管理**:允许消费者注册、登录,并管理他们的个人资料和预约历史。 2. **家政人员管理**:家政服务人员可以注册并更新自己的个人信息、服务类别和服务时间。 3. **服务预约**:消费者可以浏览不同的家政服务选项,选择合适的服务人员,并在线预约服务。 4. **订单管理**:系统支持订单的创建、跟踪和管理,包括订单的确认、完成和评价。 5. **评价系统**:消费者可以在家政服务完成后对服务进行评价,帮助提高服务质量和透明度。 6. **后台管理**:管理员可以管理用户、家政人员信息、服务类别、预约订单以及处理用户反馈。 系统采用Java语言开发,使用MySQL数据库进行数据存储,通过B/S架构实现用户与服务的在线交互。系统设计考虑了不同用户角色的需求,包括管理员、家政服务人员和普通用户,每个角色都有相应的权限和功能。此外,系统还采用了软件组件化、精化体系结构、分离逻辑和数据等方法,以便于未来的系统升级和维护。 智能家政保洁预约系统通过提供一个集中的平台,不仅方便了消费者的预约和管理,也为家政服务人员提供了一个展示和推广自己服务的机会。同时,系统的后台管理功能为家政公司提供了强大的数据支持和决策辅助,有助于提高服务质量和管理效率。该系统的设计与实现,标志着家政保洁服务向现代化和网络化的转型,为管理决策和控制提供保障,是行业发展中的重要里程碑。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值