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: 也可能是,他们 ...
随机推荐
- SpringMVC之添加照片并修改照片名字
@RequestMapping(value="/addIdcardsSubmit",method={RequestMethod.POST,RequestMethod.GET}) p ...
- 用PHP实现的快速排序算法(支持记录原始数组下标)
代码如下 <?php /** * 快速排序 */ define("MAX_LENGTH_INSERT_SORT", 7); class QuickSort { /** * 交 ...
- C++走向远洋——59(项目三、图形面积、抽象类)
*/ * Copyright (c) 2016,烟台大学计算机与控制工程学院 * All rights reserved. * 文件名:text.cpp * 作者:常轩 * 微信公众号:Worldhe ...
- Vue.js——学习笔记(一)
Vue-自学笔记 Vue (读音 /vjuː/,类似于 view) 是一套用于构建用户界面的渐进式框架.与其它大型框架不同的是,Vue 被设计为可以自底向上逐层应用.Vue 的核心库只关注视图层,不仅 ...
- 达拉草201771010105《面向对象程序设计(java)》第十四周学习总结
达拉草201771010105<面向对象程序设计(java)>第十四周学习总结 第一部分:理论知识 布局管理器: 布局管理器是一组类. 实现java.awt.LayoutManager接口 ...
- Elasticsearch系列---深入全文搜索
概要 本篇介绍怎样在全文字段中搜索到最相关的文档,包含手动控制搜索的精准度,搜索条件权重控制. 手动控制搜索的精准度 搜索的两个重要维度:相关性(Relevance)和分析(Analysis). 相关 ...
- typescript 02 数据类型
---恢复内容开始--- 1.数据类型 ts为了使代码更加规范并利于维护,增加了类型校验 提供了以下几种类型 布尔类型 boolean 数字类型 number 字符串类型 string 数组类型 ar ...
- 【Python3】HTML基础
[web前端]HTML基础 一.BS模式 BS(Browser-Server)模式:顾名思义为浏览器-服务器的意思,对比的话类似我们PC上面浏览器使用的产品即为BS模式产品,例如google doc. ...
- 合并.ts文件 无需软件
cmd 命令直接输入: copy /b D:\temp\*.ts D:\new.ts D盘temp目录的ts文件 合并 并输出到 D盘 new.ts文件
- CSS-水平居中、垂直居中、水平垂直居中
1.水平居中 水平居中可分为行内元素水平居中和块级元素水平居中 1.1 行内元素水平居中 这里行内元素是指文本text.图像img.按钮超链接等,只需给父元素设置text-align:center即可 ...