zoukankan      html  css  js  c++  java
  • cf 443B Kolya and Tandem Repeat

    B. Kolya and Tandem Repeat
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string.

    Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large could l be?

    See notes for definition of a tandem repeat.

    Input

    The first line contains s (1 ≤ |s| ≤ 200). This string contains only small English letters. The second line contains number k (1 ≤ k ≤ 200) — the number of the added characters.

    Output

    Print a single number — the maximum length of the tandem repeat that could have occurred in the new string.

    Sample test(s)
    input
    aaba
    2
    output
    6
    input
    aaabbbb
    2
    output
    6
    input
    abracadabra
    10
    output
    20
    Note

    A tandem repeat of length 2n is string s, where for any position i (1 ≤ i ≤ n) the following condition fulfills: si = si + n.

    In the first sample Kolya could obtain a string aabaab, in the second — aaabbbbbb, in the third — abracadabrabracadabra.

    大力出奇迹2333

    /*************************************************************************
        > File Name: code/2015summer/#3/A.cpp
        > Author: 111qqz
        > Email: rkz2013@126.com 
        > Created Time: 2015年07月28日 星期二 12时27分08秒
     ************************************************************************/
    
    #include<iostream>
    #include<iomanip>
    #include<cstdio>
    #include<algorithm>
    #include<cmath>
    #include<cstring>
    #include<string>
    #include<map>
    #include<set>
    #include<queue>
    #include<vector>
    #include<stack>
    #define y0 abc111qqz
    #define y1 hust111qqz
    #define yn hez111qqz
    #define j1 cute111qqz
    #define tm crazy111qqz
    #define lr dying111qqz
    using namespace std;
    #define REP(i, n) for (int i=0;i<int(n);++i)  
    typedef long long LL;
    typedef unsigned long long ULL;
    const int N=1E4+5;
    char a[N];
    int k;
    int main()
    {
    
        cin>>a>>k;
        int l=strlen(a);
        int m,ans;
        m=l+k;
        if (m%2==1) m--;
        if(k>=l)
        {
        cout<<m<<endl;
        return 0;
        }
        int max=0;
        for(int i = 0 ; i < l ; i++)
        {
            for(int j = 1 ; j <= l-i;j++)
            {
            ans = 0;
                for(int o = i ; o < i+j ; o++)
                {
            
                    if(o+j>=l&&o+j<l+k)
                        ans++;
                    else if(a[o]==a[o+j])
                         ans++;
                }
                if(ans==j&&2*ans>max)
                  max=2*ans;
            }
        }
        cout<<max<<endl;
        return 0;
    }
  • 相关阅读:
    Python-append()/extend()
    HTML标签
    字符实体
    css选择器
    边框属性
    背景属性
    文本属性
    字体属性
    给标签起名字
    JS数据类型
  • 原文地址:https://www.cnblogs.com/111qqz/p/4684777.html
Copyright © 2011-2022 走看看