日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Frog Jumps CodeForces - 1324C(二分)

發(fā)布時間:2023/12/15 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Frog Jumps CodeForces - 1324C(二分) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

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為起點跳。如果當前跳數(shù)無法找到下一個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(二分)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。