标签:style http color os for rgb
题目连接: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
Codeforces 442B Kolya and Tandem Repeat(暴力)
标签:style http color os for rgb
原文地址:http://blog.csdn.net/keshuai19940722/article/details/35878073