纯粹练JAVA....

B. Kolya and Tandem Repeat
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more
characters to the right of the string.

Then Borya came and said that the new string contained a tandem repeat of length l as a
substring. How large could l be?

See notes for definition of a tandem repeat.

Input

The first line contains s (1 ≤ |s| ≤ 200). This string
contains only small English letters. The second line contains number k (1 ≤ k ≤ 200)
— the number of the added characters.

Output

Print a single number — the maximum length of the tandem repeat that could have occurred in the new string.

Sample test(s)
input
aaba
2
output
6
input
aaabbbb
2
output
6
input
abracadabra
10
output
20
Note

A tandem repeat of length 2n is string s, where for
any position i (1 ≤ i ≤ n) the following
condition fulfills: si = si + n.

In the first sample Kolya could obtain a string aabaab, in the second — aaabbbbbb,
in the third — abracadabrabracadabra.


import java.util.*;

public class Main
{
public static void main(String[] args)
{
Scanner cin=new Scanner(System.in);
String str=cin.next();
int k=cin.nextInt();
int ans=2;
while(k-->0)
{
str=str+"*";
for(int len=ans/2;2*len<=str.length();len++)
{
for(int i=0;i+2*len-1<str.length();i++)
{
boolean flag=true;
int u=i,v=i+len;
for(int j=0;j<len&&flag;j++)
{
if(str.charAt(u+j)=='*'||str.charAt(v+j)=='*') continue;
if(str.charAt(u+j)==str.charAt(v+j)) continue;
else flag=false;
}
if(flag)
ans=Math.max(ans,len*2);
}
}
}
System.out.println(ans);
}
}

版权声明:来自: 代码代码猿猿AC路 http://blog.csdn.net/ck_boss

Codeforces 443 B. Kolya and Tandem Repeat的更多相关文章

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

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

  2. Codeforces 443 B Kolya and Tandem Repeat【暴力】

    题意:给出一个字符串,给出k,可以向该字符串尾部添加k个字符串,求最长的连续重复两次的子串 没有想出来= =不知道最后添加的那k个字符应该怎么处理 后来看了题解,可以先把这k个字符填成'*',再暴力枚 ...

  3. cf443B Kolya and Tandem Repeat

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

  4. Kolya and Tandem Repeat

     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 Round 253 (Div. 2)

    layout: post title: Codeforces Round 253 (Div. 2) author: "luowentaoaa" catalog: true tags ...

  9. 33、VCF格式

    转载:http://blog.sina.com.cn/s/blog_7110867f0101njf5.html http://www.cnblogs.com/liuhui0622/p/6246111. ...

随机推荐

  1. Qt计算器开发(二):信号槽实现数学表达式合法性检查

    表达式的合法性 由于我们的计算器不是单步计算的,所以我们能够一次性输入一个长表达式.然而假设用户输入的长表达式不合法的话,那么就会引发灾难.所以有必要对于用户的输入做一个限制. 一些限制举例: 比方, ...

  2. 最佳新秀SSH十六Struts2它是如何工作的内部

    前面说完了Spring.Hibernate,非常自然今天轮到struts了.struts的核心原理就是通过拦截器来处理client的请求,经过拦截器一系列的处理后,再交给Action.以下先看看str ...

  3. 数据结构之计算器的实现(JAVA)(四)

    原理: 1.将中序表达式变化兴许表达式 2.当前字符为数字,将该数字放入栈中 3.当前字符为操作符,从栈中取出两个树,依据操作符来运算,将运算结果放入到栈中 4.反复,直到将字符操作完.此时栈中仅仅剩 ...

  4. HDU 4508 沼泽湿地系列故事——记住减肥I (2013腾讯编程马拉松预赛第一)

    pid=4508">http://acm.hdu.edu.cn/showproblem.php?pid=4508 题目大意: 给定一些数据. 每组数据以一个整数n開始,表示每天的食物清 ...

  5. maven snapshot和release版本号之间的差

    在使用maven过程.我们经常会在不稳定的状态有很多公共图书馆在发展阶段.需要改变在任何时间和公布,你可能有一天一次发布.经验bug时间,甚至一天公布N次要.我们知道,.maven依赖管理是基于管理的 ...

  6. Git Flow流程

    # 1. clone远程仓库到本地 git clone git@git.oschina.net:huogh/muzhifm_xxx.git ​ # 2. 使用远程分支origin/dev创建本地分支d ...

  7. POJ 1659 Frogs&#39; Neighborhood(度序列组成)

    意甲冠军  中国 依据Havel-Hakimi定理构图即可咯  先把顶点按度数从大到小排序  可图的话  度数大的顶点与它后面的度数个顶点相连肯定是满足的  出现了-1就说明不可图了 #include ...

  8. Swift学习 --- 2.3和字符串

    1.创建一个空字符串,并通过推理的字符串是空的 <span style="font-size:18px;"> var str = "" var st ...

  9. 几点思考-人生哲学,生活方式---ShinePans

    美结账时账单住酒店一晚800元.她抱怨太贵.经理说这是标准收费,带泳池的酒店.健身房和wifi. 美女说自己全然没使用,经理说饭店有提供.是她自己不用. 女客人打开皮包掏钱付账.但说要扣除经理和她共度 ...

  10. 云梯vpn

    刚和大饼合买了一个云梯的vpn 表示可以把俺的优惠连接放出来了 貌似必须是新注册用户才能够享用优惠 http://protizi.com/?r=5e3fecd7eae558ec 把云梯推荐给朋友们 让 ...