There is a frog staying to the left of the string s=s1s2…sn consisting of n characters (to be more precise, the frog initially stays at the cell 0). Each character of s is either ‘L’ or ‘R’. It means that if the frog is staying at the i-th cell and the i-th character is ‘L’, the frog can jump only to the left. If the frog is staying at the i-th cell and the i-th character is ‘R’, the frog can jump only to the right. The frog can jump only to the right from the cell 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-th cell. The frog chooses some positive integer value d before the first jump (and cannot change it later) and jumps by no more than d cells at once. I.e. if the i-th character is ‘L’ then the frog can jump to any cell in a range [max(0,i−d);i−1], and if the i-th character is ‘R’ then the frog can jump to any cell in a range [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 such that the frog can reach the cell n+1 from the cell 0 if it can jump by no more than d cells at once. It is guaranteed that it is always possible to reach n+1 from 0.

You have to answer t independent test cases.

Input
The first line of the input contains one integer t (1≤t≤104) — the number of test cases.

The next t lines describe test cases. The i-th test case is described as a string s consisting of at least 1 and at most 2⋅105 characters ‘L’ and ‘R’.

It is guaranteed that the sum of lengths of strings over all test cases does not exceed 2⋅105 (∑|s|≤2⋅105).

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

Example
Input
6
LRLRRLL
L
LLR
RRRR
LLLLLL
R
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 to n+1.

In the third test case of the example, the frog can choose d=3, jump to the cell 3 from the cell 0 and then to the cell 4 from the cell 3.

In the fourth test case of the example, the frog can choose d=1 and jump 5 times to the right.

In the fifth test case of the example, the frog can only jump directly from 0 to n+1.

In the sixth test case of the example, the frog can choose d=1 and jump 2 times to the right.
思路:我们二分去找答案,在判断的时候,在能跳到的范围内去找R,如果找到R,再以这个R为起点跳。如果当前跳数无法找到下一个R,就不可以。
代码如下:

#include<bits/stdc++.h>
#define ll long long
using namespace std;const int maxx=2e5+100;
string s;
int n;inline int fcs(int ts,int num)
{if(num+ts>=n+1) return 1;for(int i=num+1;i<=num+ts;i++){if(s[i]=='R') return fcs(ts,i);}return 0;
}
int main()
{int t;scanf("%d",&t);while(t--){cin>>s;n=s.length();s='&'+s;int l=1,r=n+1,mid;int ans;while(l<=r){mid=l+r>>1;if(fcs(mid,0)){ans=mid;r=mid-1;}else l=mid+1;}cout<<ans<<endl;}return 0;
}

努力加油a啊,(o)/~

Frog Jumps CodeForces - 1324C(二分)相关推荐

  1. [codeforces 1324C] Frog Jumps 一直向右+边界处理

    Codeforces Round #627 (Div. 3)   比赛人数6434 [codeforces 1324C]  Frog Jumps   一直向右+边界处理 总目录详见https://bl ...

  2. Match Points CodeForces 1156C 二分答案

    CodeForces 1156C Match Points 传送门:https://codeforces.com/problemset/problem/1156/C You are given a s ...

  3. Frog Jumps

    There is a frog staying to the left of the string s=s1s2-sn consisting of n characters (to be more p ...

  4. Codeforces 650B 二分

    题目:http://codeforces.com/problemset/problem/650/B 题意: :给n张图片循环可看,每张图片的朝向为横(w)|竖(v),但是手机是竖直放置的.开始时打开的 ...

  5. CodeForces - 786C——二分+模拟?

    [题目描述] Rick and Morty want to find MR. PBH and they can't do it alone. So they need of Mr. Meeseeks. ...

  6. Frodo and pillows CodeForces - 760B 二分 注意l和r的选择

    以后写l和r的初始值的时候,在不影响合理性的前提下,尽量写大一点 比如下面这个代码,如果r不加以或者l==0就不行 #include <iostream> #include <cst ...

  7. [codeforces 1324D] Pair of Topics 分而治之+排列组合

    Codeforces Round #627 (Div. 3)   比赛人数6434 [codeforces 1324C]  Frog Jumps   一直向右+边界处理 总目录详见https://bl ...

  8. A. Frog Jumping

    传送门 A. Frog Jumping A frog is currently at the point 00 on a coordinate axis OxOx. It jumps by the f ...

  9. Gradle | Gradle构建之Groovy语言基础

    前言 Gradle的构建脚本是采用Groovy语言编写的.Groovy是Java平台上设计的一种强大的.可选类型和动态的语言.Groovy可以无缝地集成任何Java程序,并立即让你的应用程序拥有强大的 ...

最新文章

  1. 构建一个react项目_您想要了解更多有关React的内容吗? 让我们构建一个游戏,然后玩。...
  2. delphi中设置系统时间方法
  3. 获取json格式字符串的简单方法
  4. android 7 蓝牙版本,[Android]Android什么版本开始支持蓝牙4.2?答案:Android 7.0
  5. 利用Python定时给女友微信发送今日天气情况,异地恋维护感情神器
  6. Java基础学习总结(56)——学Java必知十大学习目标
  7. esxi 环境 西数硬盘测试软件,西数硬盘原厂检测工具(Western Digital Data LifeGuard Diagnostics)...
  8. 第六次毕业设计任务书
  9. 关于请设置注册表项Framewoke.....初始化错误的解决办法
  10. UEFI是什么?与BIOS的区别在哪?
  11. mysql设置不用科学记数法,关闭科学记数法MySQL
  12. 闻道有先后,术业有专攻
  13. 笔记连载 | Day1数字电路基础篇
  14. pygame系列_百度随心听_完美的UI设计
  15. java调用迅雷_java jna调用迅雷接口下载
  16. 核主元分析 KPCA及matlab代码,主要用于数据降维。
  17. 发力电商培训 淘宝天下小二助力品牌商家成长
  18. [转帖]房博士教你购房(四)
  19. C语言看计算机基础(一)
  20. Acrobat Pro DC 教程:如何从 PDF 中提取页面?

热门文章

  1. 74cms3.0安装以及cmsSQL注入漏洞详解
  2. 面试中关于String、StringBuffer、StringBuilder的频率最高问题
  3. java hashmap遍历顺序_Java中HashMap遍历的两种方式
  4. tfrcw函数用法_open函数
  5. 会做饭的机器人曰记_CCTV.com
  6. Android开发之部分字符串可实现超链接点击事件的方法
  7. 拉文大学计算机科学,拉文大学
  8. 自制最小的无盘网络服务器,无盘网络终极制作2003服务器端安装准备
  9. 初探Java设计模式1:创建型模式(工厂,单例等)
  10. Java基本类型练习1