A. Cut and Paste(模拟)

A. Cut and Paste

link

题意:给定原始字符串s,给定下标x。光标依次向后移动直至x处,每次对后半段执行光标所在位置相对于次复制粘贴操作,问最终的字符串长度。

例子及解释:
5
231

  • Step 1, Move once: we get ℓ=1.
  • Step 2, Cut once: we get s= 2 and c= 31.
  • Step 3, Paste sℓ= 2 times: we get s= 23131.
  • Step 4: ℓ=1≠x=5, so we return to step 1.

  • Step 1, Move once: we get ℓ=2.
  • Step 2, Cut once: we get s= 23 and c= 131.
  • Step 3, Paste sℓ= 3 times: we get s= 23131131131.
  • Step 4: ℓ=2≠x=5, so we return to step 1.

  • Step 1, Move once: we get ℓ=3.
  • Step 2, Cut once: we get s= 231 and c= 31131131.
  • Step 3, Paste sℓ= 1 time: we get s= 23131131131.
  • Step 4: ℓ=3≠x=5, so we return to step 1.

  • Step 1, Move once: we get ℓ=4.
  • Step 2, Cut once: we get s= 2313 and c= 1131131.
  • Step 3, Paste sℓ= 3 times: we get s= 2313113113111311311131131.
  • Step 4: ℓ=4≠x=5, so we return to step 1.

  • Step 1, Move once: we get ℓ=5.
  • Step 2, Cut once: we get s= 23131 and c= 13113111311311131131.
  • Step 3, Paste sℓ= 1 times: we get s= 2313113113111311311131131.
  • Step 4: ℓ=5=x, so we stop.

题目都说了最后串会很长,直接模拟肯定不行。就先把字符串增加到n的长度,然后记下最后的长度就好了
注意再最后的%mod的时候要+mod再说,否则会产生负数
用while就不会tle在test24服了我真是纯种憨憨

int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        string s;
        cin>>s;
        int f=0;
        while(s.length()<n){
            int len=s.length();
            for(int j=0;j<s[f]-'1';j++){
                s+=s.substr(f+1,len-f-1);
            }

            f++;
        }
        LL last=s.length();
        while(f<n){
            last=(last+1ll*(s[f]-'1')*(last-1ll-1ll*f)%MOD+MOD)%MOD;//注意这里+MOD
            f++;
        }
        cout<<last<<endl;
    }
    return 0;
}

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值