C. Frog Jumps
题目链接-C. Frog Jumps
题目大意
青蛙过河,河中每个石子有自己的属性L和R,L只能向左跳,R只能向右跳,每次最多跳k步,求能过河的最小的k值使得青蛙能从0跳到n+1
解题思路
显然青蛙应该避免跳到L上,所以要找最长的连续L串(即判断两个R之间的最大距离),长度再加1即可
附上代码
#include<bits/stdc++.h>
#define int long long
#define lowbit(x) (x &(-x))
using namespace std;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-10;
const int M=1e9+7;
const int N=1e5+5;
typedef long long ll;
typedef pair<int,int> PII;
string s;
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int t;
cin>>t;
while(t--){
cin>>s;
int ans=-INF,cnt=0;
for(int i=0;i<s.length();i++){
if(s[i]=='L')
cnt++;
else{
ans=max(ans,cnt);
cnt=0;
}
}
cout<<max(ans,cnt)+1<<endl;
}
return 0;
}