codeforces 1324 C. Frog Jumps

思维很重要🤔
这种题就不能单单想暴力了
首先这个题正确的思维是:假设0位置和n+1是‘R’,找除了0到n+1以外最远的R像个距离,该距离就是d。
这一题的关键是理解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)].中的 [max(0,i−d);i−1]和[i+1;min(n+1;i+d)]。
当i位置是L时,跳的范围时i-d(当i-d<0时取0)到i-1,当i的位置时R时跳的范围是i+1到i+d(当i+d>n+1时取n+1),当时我就吧跳的范围长度当作随i的变化时刻时刻变化的啦,没有了解到这两个式子的真正含义。┭┮﹏┭┮,还要努力。
这样的话,这题的思维就可以理解了。
在这里插入图片描述
Example
input

6
LRLRRLL
L
LLR
RRRR
LLLLLL
R

output

3
2
3
1
7
1
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
    string s;
    cin>>s;
    int m=-1,step=0;
    int len=s.length();
    for(int i=0;i<len;i++)
    {

        if(s[i]=='L')
        step++;
    else if(s[i]=='R')
    {
        m=max(m,step);
        step=0;
    }

    }
    m=max(m,step);
    if(m==-1)
        m=len;
    cout<<m+1<<endl;
}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值