CodeForces 443B Kolya and Tandem Repeat

时间:2023-03-09 19:37:32
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+; int k;
char str[M];
int ans, len, lenth;
bool check( int x, int y ) { // 判断字符串中[x,y]与[y+1,y-x+1]是否相同
if( x >= len ) return true;
for( int i=x; i<=y; i++ ) {
if( i+lenth >= len ) break;
if( str[i] != str[i+lenth] ) return false;
}
return true;
}
void solve() {
len = strlen( str );
ans = ;
for( int i=; i<len+k-; i++ ) {
for( int j=i; j<len+k; j++ ) {
lenth = j+-i;
if( j+lenth >= len+k ) break;
if( lenth <= ans ) continue;
if( check( i, j ) )
ans = max( ans, lenth );
if( ans == (len+k)/ ) return;
}
}
}
int main() {
while( ~scanf("%s%d", str, &k ) ) {
solve();
printf("%d\n", ans* );
}
return ;
}