码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2014-09-02 00:07:13      阅读:205      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   io   ar   for   div   log   

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

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

#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 int
char 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(暴力枚举)

标签:style   blog   color   os   io   ar   for   div   log   

原文地址:http://www.cnblogs.com/zywscq/p/3950455.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!