zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 1 B. Queries on a String 暴力

    B. Queries on a String

    Time Limit: 20 Sec

    Memory Limit: 256 MB

    题目连接

    http://codeforces.com/contest/598/problem/B

    Description

    You are given a string s and should process m queries. Each query is described by two 1-based indices liri and integer ki. It means that you should cyclically shift the substring s[li... riki times. The queries should be processed one after another in the order they are given.

    One operation of a cyclic shift (rotation) is equivalent to moving the last character to the position of the first character and shifting all other characters one position to the right.

    For example, if the string s is abacaba and the query is l1 = 3, r1 = 6, k1 = 1 then the answer is abbacaa. If after that we would process the query l2 = 1, r2 = 4, k2 = 2 then we would get the string baabcaa.

    Input

    The first line of the input contains the string s (1 ≤ |s| ≤ 10 000) in its initial state, where |s| stands for the length of s. It contains only lowercase English letters.

    Second line contains a single integer m (1 ≤ m ≤ 300) — the number of queries.

    The i-th of the next m lines contains three integers liri and ki (1 ≤ li ≤ ri ≤ |s|, 1 ≤ ki ≤ 1 000 000) — the description of the i-th query.

    Output

    Print the resulting string s after processing all m queries.

    Sample Input

    abacaba
    2
    3 6 1
    1 4 2

    Sample Output

    baabcaa

    HINT

    题意

    给你一个字符串,然后有Q次操作,每次操作可以使得区间的字符串向右平移K个字符

    然后问你最后的字符是什么模样

    题解:

    询问只有300个,所以可以直接暴力就好了

    代码

    #include<iostream>
    using namespace std;
    
    int main()
    {
        string s1,s2;
        cin>>s1;
        s2=s1;
        int q;cin>>q;
        while(q--)
        {
            int l,r,k;cin>>l>>r>>k;
            l--,r--;
            int len = r-l+1;k%=len;
            for(int i=0;i<len;i++)
            {
                s2[(i+k)%len+l]=s1[l+i];
            }
            for(int i=l;i<=r;i++)
                s1[i]=s2[i];
        }
        cout<<s1<<endl;
    }
  • 相关阅读:
    P1121 环状最大两段子段和
    无题
    cdoj 1485 柱爷搞子串 sam treap
    自然数幂和
    Gym 100341C AVL Trees NTT
    线性筛分解质因子
    codeforces 366 Ant Man dp
    UVALive 6914 Maze Mayhem 轮廓线dp
    hdu 5790 Prefix 字典树 主席树
    莫比乌斯反演个人小结
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4966139.html
Copyright © 2011-2022 走看看