Codeforces 442B Kolya and Tandem Repeat(暴力)

题目连接: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", (n + len) / 2 * 2);
    } else {
        for (int i = len; i >= 0; i--) {
            if (judge(i)) {
                printf("%d\n", i*2);
                break;
            }
        }
    }
    return 0;
}

Codeforces 442B Kolya and Tandem Repeat(暴力),布布扣,bubuko.com

时间: 2024-08-05 07:09:27

Codeforces 442B Kolya and Tandem Repeat(暴力)的相关文章

CodeForces 443B Kolya and Tandem Repeat

题目:Click here 题意:给定一个字符串(只包含小写字母,并且最长200)和一个n(表示可以在给定字符串后面任意加n(<=200)个字符).问最长的一条子串长度,子串满足前半等于后半. 分析:暴力~~~~~~ #include <bits/stdc++.h> using namespace std; typedef long long ll; const int INF = 0x3f3f3f3f; const int M = 3e5+3; int k; char str[M];

Codeforces Round #253 (Div. 2) B - Kolya and Tandem Repeat

本题要考虑字符串本身就存在tandem, 如测试用例 aaaaaaaaabbb 3 输出结果应该是8而不是6,因为字符串本身的tanderm时最长的 故要考虑字符串本身的最大的tanderm和添加k个字符后最大的tanderm #include <iostream> #include <vector> #include <algorithm> #include <string> #include <set> using namespace std

CQUOJ 10672 Kolya and Tandem Repeat

A. Kolya and Tandem Repeat Time Limit: 2000ms Memory Limit: 262144KB 64-bit integer IO format: %I64d      Java class name: Any Submit Status PID: 10672 Kolya got string s for his birthday, the string consists of small English letters. He immediately

CF B. Kolya and Tandem Repeat

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. H

Codeforces 443 B Kolya and Tandem Repeat【暴力】

题意:给出一个字符串,给出k,可以向该字符串尾部添加k个字符串,求最长的连续重复两次的子串 没有想出来= =不知道最后添加的那k个字符应该怎么处理 后来看了题解,可以先把这k个字符填成'*',再暴力枚举起点和长度,找出最大的长度 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include <cmath> 5 #include<stack> 6 #include<

Codeforces 442B Andrey and Problem(贪心)

题目链接:Codeforces 442B Andrey and Problem 题目大意:Andrey有一个问题,想要朋友们为自己出一道题,现在他有n个朋友,每个朋友想出题目的概率为pi,但是他可以同时向多个人寻求帮助,不过他只能要一道题,也就是如果他向两个人寻求帮助,如果两个人都成功出题,也是不可以的. 解题思路:贪心,从概率最大的人开始考虑,如果询问他使得概率变大,则要询问. #include <cstdio> #include <cstring> #include <a

Codeforces Round #224 (Div. 2) D 暴力搜索加记忆化

题意读了半年,英语太渣,题意是摆两个棋子在棋盘上作为起点,但是起点不能在#上,然后按照图的指示开始走, < 左 > 右 ^上 v下,走的时候只能按照图的指示走,如果前方是 #的话,可以走进去,但是 走进去之后便不能再走了,走的途中两个棋子不能相碰,但是最终都走到同一个#里是没事的,并且若是能走 无限步的话 输出 -1, 例如  > < 这样左右左右的走就能无限走,然后问你 两个棋子走的最大步数的和 一开始被输出-1给困住了,因为除了 .> <这样以外  还可以刚好形成一

codeforces 514C Watto and Mechanism (分段暴力)

codeforces 514C Watto and Mechanism (分段暴力) 题意: 给出一个包含n个单词的字典,给出m个待查询单词,如果单词在有且仅有一个字符不相同的情况下可以在字典里找到,则输出YES,否则输出NO 限制: 0 <= n,m <= 3*10^5; 总字符长度不大于6*10^5 思路: 分段暴力. 以查询单词长度为500分段: 查询单词长度<500则:采用set查询,复杂度为600*500*500=1.5*10^8 查询单词长度>500则:暴力查询,复杂度

Codeforces 827E Rusty String - 快速傅里叶变换 - 暴力

Grigory loves strings. Recently he found a metal strip on a loft. The strip had length n and consisted of letters "V" and "K". Unfortunately, rust has eaten some of the letters so that it's now impossible to understand which letter was