题意:给出一个字符串,给出k,可以向该字符串尾部添加k个字符串,求最长的连续重复两次的子串

没有想出来= =不知道最后添加的那k个字符应该怎么处理

后来看了题解,可以先把这k个字符填成'*',再暴力枚举起点和长度,找出最大的长度

 #include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
using namespace std; typedef long long LL;
const int INF = (<<)-;
const int mod=;
const int maxn=;
char s[maxn];
int len; int main(){
int k;
cin>>s;
int len=strlen(s);
cin>>k;
for(int i=len;i<len+k;i++) s[i]='*'; int ans=-;
len=len+k;
for(int i=;i<len;i++){
for(int j=;*j+i<=len;j++){
int flag=;
for(int t=i;t<i+j;t++){
if(s[t]!=s[t+j]&&s[t+j]!='*') {
flag=;
break;
}
}
if(flag) ans=max(ans,j*);
}
} printf("%d\n",ans);
return ;
}

Codeforces 443 B Kolya and Tandem Repeat【暴力】的更多相关文章

  1. Codeforces 443 B. Kolya and Tandem Repeat

    纯粹练JAVA.... B. Kolya and Tandem Repeat time limit per test 2 seconds memory limit per test 256 megab ...

  2. codeforces 443 B. Kolya and Tandem Repeat 解题报告

    题目链接:http://codeforces.com/contest/443/problem/B 题目意思:给出一个只有小写字母的字符串s(假设长度为len),在其后可以添加 k 个长度的字符,形成一 ...

  3. Kolya and Tandem Repeat

     Kolya and Tandem Repeat time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  4. cf443B Kolya and Tandem Repeat

    B. Kolya and Tandem Repeat time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  5. CF B. Kolya and Tandem Repeat

    Kolya got string s for his birthday, the string consists of small English letters. He immediately ad ...

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

    本题要考虑字符串本身就存在tandem, 如测试用例 aaaaaaaaabbb 3 输出结果应该是8而不是6,因为字符串本身的tanderm时最长的 故要考虑字符串本身的最大的tanderm和添加k个 ...

  7. CodeForces 443B Kolya and Tandem Repeat

    题目:Click here 题意:给定一个字符串(只包含小写字母,并且最长200)和一个n(表示可以在给定字符串后面任意加n(<=200)个字符).问最长的一条子串长度,子串满足前半等于后半. ...

  8. Codeforces Gym 100803F There is No Alternative 暴力Kruskal

    There is No Alternative 题目连接: http://codeforces.com/gym/100803/attachments Description ICPC (Isles o ...

  9. Codeforces Beta Round #13 E. Holes 分块暴力

    E. Holes Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/13/problem/E Des ...

随机推荐

  1. Grid分组特性

    Ext.onReady(function () {                Ext.define('personInfo', {                    extend: 'Ext. ...

  2. js-jQuery对象与dom对象相互转换

    http://blog.csdn.net/jueshengtianya/article/details/8823091   核心提示:jquery选择器得到的jquery对象和标准的 javascri ...

  3. JavaWeb-JDK下载安装

    JDK官方下载地址:http://www.oracle.com/index.html JDK下载: 64位的下64的 JDK安装:(这是32位的) JDK部署测试:(配置环境变量) JAVA_HOME ...

  4. Linux :Can't start up: not enough memory

    http://stackoverflow.com/questions/9634577/linux-cant-start-up-not-enough-memory

  5. ExtJs之Ext.apply

    <!DOCTYPE html> <html> <head> <title>ExtJs</title> <meta http-equiv ...

  6. js截取指定字节长度的字符串

    默认的截取字符串都是根据字符长度或位置截取的,典型的两个方法是substr和substring. 这样导致的问题是截取同样长度的字符串时,多字节字符(汉字等)和单字节字符(半角英文字母.半角数字)占的 ...

  7. android学习--radiogroup学习

    这个阶段在学习android的相关基本UI现将相关练习的代码粘贴在此便于后期学习之用(radio控件) 效果图:   main_layout.xml <?xml version="1. ...

  8. SQLHelper.cs的经典代码-存储过程

    using System; using System.Collections.Generic; using System.Text; using System.Collections; using S ...

  9. Struts2笔记——struts常用标签

    使用struts标签前,首先要配置struts2架构,然后导入标签库,jsp插入如下语句: <%@taglib uri="/struts-tags" prefix=" ...

  10. Android从零单排之自动跟新

    自动更新原理 当我们发布我们的应用程序的时候,肯定会想到后续版本的更新,那么该怎么对我们的程序进行更新呢? 更新APK的原理实际上就是比较程序中的AndroidManifest.xml中的versio ...