div 3 frog jump
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.
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 00 to n+1n+1.
In the third test case of the example, the frog can choose d=3d=3, jump to the cell 33 from the cell 00 and then to the cell 44 from the cell 33.
In the fourth test case of the example, the frog can choose d=1d=1 and jump 55 times to the right.
In the fifth test case of the example, the frog can only jump directly from 00 to n+1n+1.
In the sixth test case of the example, the frog can choose d=1d=1 and jump 22 times to the right.
这个题可以看作为在一个字符串中相邻的两个L之间最远的距离是多少,如果能看到这里代码也就比较好写了,但是当时没看出来
#include<iostream>
#include<cstring>
const long long maxn=2e5+;
char s[maxn];
using namespace std;
int main(){
int t,d,x;
cin>>t;
while(t--){
d=,x=; //每次操作时对这两个数进行重制
cin>>s;
int l=strlen(s);
for(int i=;i<l;i++){
if(s[i]=='R'){
x=;
}
else{
x++;
if(x>d) d=x;
}
}
cout<<d+<<endl;
}
}
div 3 frog jump的更多相关文章
- [LeetCode] Frog Jump 青蛙过河
A frog is crossing a river. The river is divided into x units and at each unit there may or may not ...
- Frog Jump
A frog is crossing a river. The river is divided into x units and at each unit there may or may not ...
- Leetcode: Frog Jump
A frog is crossing a river. The river is divided into x units and at each unit there may or may not ...
- [Swift]LeetCode403. 青蛙过河 | Frog Jump
A frog is crossing a river. The river is divided into x units and at each unit there may or may not ...
- [leetcode]403. Frog Jump青蛙过河
A frog is crossing a river. The river is divided into x units and at each unit there may or may not ...
- LeetCode403. Frog Jump
A frog is crossing a river. The river is divided into x units and at each unit there may or may not ...
- [LeetCode] 403. Frog Jump 青蛙跳
A frog is crossing a river. The river is divided into x units and at each unit there may or may not ...
- [leetcode] 403. Frog Jump
https://leetcode.com/contest/5/problems/frog-jump/ 这个题目,还是有套路的,之前做过一道题,好像是贪心性质,就是每次可以跳多远,最后问能不能跳到最右边 ...
- 403. Frog Jump
做完了终于可以吃饭了,万岁~ 假设从stone[i]无法跳到stone[i+1]: 可能是,他们之间的距离超过了stone[i]所能跳的最远距离,0 1 3 7, 从3怎么都调不到7: 也可能是,他们 ...
随机推荐
- 算法基本概念及常用算法Python实现
基础算法概念: 时间复杂度 时间复杂度是从其增速的角度度量的, 时间复杂度一般用大O法表示. 递归 递归指的是调用自己的函数. 如果使用循环,程序性能可能更高: 如果使用递归,程序可能更容易理解. ...
- Canvas和svg总结比较
Canvas 基本用法 getContext() 描边和填充 strokeStyle:设置描边样式fillStyle:设置填充样式stroke():描边fill():填充 绘制矩形 fillRect( ...
- Python——5函数
*/ * Copyright (c) 2016,烟台大学计算机与控制工程学院 * All rights reserved. * 文件名:text.cpp * 作者:常轩 * 微信公众号:Worldhe ...
- Web环境从Apache转Nginx后页面报404错误
问题原因: Apache支持伪静态规则在项目的入口目录有个.htaccess文件,Apache默认识别此文件内容, 但是Nginx不识别.htaccess文件,导致伪静态规则失效,从而无法解析url地 ...
- JS 增删改查操作XML
效果图: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <titl ...
- Python知识点 - Xpath提取某个标签,需要转换为HTML。
# lxml转Html from lxml import etree from HTMLParser import HTMLParser def lxml_to_html(text:etree ...
- Tomcat8优化
一.Tomcat8优化 Tomcat服务器在JavaEE项目中使用率非常高,所以在生产环境对Tomcat的优化也变得非常重要了. 对于Tomcat的优化,主要是从2个方面入手,一是,Tomcat自身的 ...
- Adobe Premiere Pro 2020破解教程
首先官网下载Adobe Creative Cloud,安装完之后使用它继续安装Pr.注意在安装之前,点击文件→首选项,先设置一下你的安装路径,没有设置则默认安装在C盘. 接着下载网上良心博主推荐的破解 ...
- Feign 第一个Feign程序 一
Feign 开源地址:https://github.com/OpenFeign/feign 1.编写接口服务 (1)导入jar包 <parent> <groupId>org.s ...
- angular -——组件样式修改不成功
angular组件样式修改不成功! 自己定义的css可以成功 组件的不行 style在模板字符串里 直接没有 class 是显示的 但是样式不生效 加上面 即可,为什么?我也不太清楚.有知道答案的请回 ...