首页 > 代码库 > Codeforces Round #253 (Div. 2)B(暴力枚举)

Codeforces Round #253 (Div. 2)B(暴力枚举)

就暴力枚举所有起点和终点就行了。

我做这题时想的太多了,最简单的暴力枚举起始点却没想到。。。应该先想最简单的方法,层层深入。

#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<map>#include<set>#include<vector>#include<algorithm>#include<stack>#include<queue>using namespace std;#define INF 1000000000#define eps 1e-8#define pii pair<int,int>#define LL long long intchar s[500];int k,ans;void check(int b,int e){    int l=e-b+1;    if(l&1) return;    else    {        int t=l/2;        for(int i=b;i<b+t;i++)        {            if(s[i]==s[t+i]||s[t+i]==0)                continue;            else return;        }        ans=max(ans,l);        return;    }}int main(){    //freopen("in7.txt","r",stdin);    //freopen("out.txt","w",stdout);    scanf("%s",s);    scanf("%d",&k);    int len=strlen(s);    int lens=len+k;    ans=0;    for(int i=0;i<lens-1;i++)    {        for(int j=i+1;j<=lens-1;j++)        {            check(i,j);        }    }    printf("%d\n",ans);    //fclose(stdin);    //fclose(stdout);    return 0;}

 

Codeforces Round #253 (Div. 2)B(暴力枚举)