zoukankan      html  css  js  c++  java
  • Codeforces 442B Kolya and Tandem Repeat(暴力)

    版权声明:本文为博主原创文章,未经博主同意不得转载。

    https://blog.csdn.net/u011328934/article/details/35878073

    题目连接:Codeforces 442B Kolya and Tandem Repeat

    题目大意:给出一个字符串,能够再加入n个字符,问说能够找到SS的子串形式,S尽量长。

    解题思路:枚举长度和起点推断就可以。超过len的能够作为随意值,可是超过len+n就不行了。

    #include <cstdio>
    #include <cstring>
    
    const int N = 205;
    
    int n, len;
    char s[N];
    
    bool judge (int l) {
    
        if (l <= n)
            return true;
    
        for (int i = 0; i < len-l+n; i++) {
    
            bool flag = true;
    
            for (int j = 0; j < l; j++) {
    
                if (i + j + l >= len + n) {
                    flag = false;
                    break;
                }
    
                if (i + j >= len || i + j + l >= len)
                    continue;
    
                if (s[i+j] == s[i+j+l])
                    continue;
    
                flag = false;
                break;
            }
    
            if (flag)
                return true;
        }
        return false;
    }
    
    int main () {
        scanf("%s%d", s, &n);
    
        len = strlen(s);
    
        if (n >= len) {
            printf("%d
    ", (n + len) / 2 * 2);
        } else {
            for (int i = len; i >= 0; i--) {
                if (judge(i)) {
                    printf("%d
    ", i*2);
                    break;
                }
            }
        }
        return 0;
    }
  • 相关阅读:
    PHP入门03 -- 数组与数据结构
    PHP入门02 -- 函数
    PHP入门01 -- 基本语法
    node文章
    Mongodb08
    Mongodb07
    ISO处理jq事件
    map
    Django自定义模板
    JS this指向
  • 原文地址:https://www.cnblogs.com/mqxnongmin/p/10851154.html
Copyright © 2011-2022 走看看