Codeforces 443 B. Kolya and Tandem Repeat
纯粹练JAVA....
2 seconds
256 megabytes
standard input
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.
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.
Print a single number — the maximum length of the tandem repeat that could have occurred in the new string.
aaba
2
6
aaabbbb
2
6
abracadabra
10
20
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的更多相关文章
- codeforces 443 B. Kolya and Tandem Repeat 解题报告
题目链接:http://codeforces.com/contest/443/problem/B 题目意思:给出一个只有小写字母的字符串s(假设长度为len),在其后可以添加 k 个长度的字符,形成一 ...
- Codeforces 443 B Kolya and Tandem Repeat【暴力】
题意:给出一个字符串,给出k,可以向该字符串尾部添加k个字符串,求最长的连续重复两次的子串 没有想出来= =不知道最后添加的那k个字符应该怎么处理 后来看了题解,可以先把这k个字符填成'*',再暴力枚 ...
- cf443B Kolya and Tandem Repeat
B. Kolya and Tandem Repeat time limit per test 2 seconds memory limit per test 256 megabytes input s ...
- Kolya and Tandem Repeat
Kolya and Tandem Repeat time limit per test 2 seconds memory limit per test 256 megabytes input s ...
- CF B. Kolya and Tandem Repeat
Kolya got string s for his birthday, the string consists of small English letters. He immediately ad ...
- Codeforces Round #253 (Div. 2) B - Kolya and Tandem Repeat
本题要考虑字符串本身就存在tandem, 如测试用例 aaaaaaaaabbb 3 输出结果应该是8而不是6,因为字符串本身的tanderm时最长的 故要考虑字符串本身的最大的tanderm和添加k个 ...
- CodeForces 443B Kolya and Tandem Repeat
题目:Click here 题意:给定一个字符串(只包含小写字母,并且最长200)和一个n(表示可以在给定字符串后面任意加n(<=200)个字符).问最长的一条子串长度,子串满足前半等于后半. ...
- Codeforces Round 253 (Div. 2)
layout: post title: Codeforces Round 253 (Div. 2) author: "luowentaoaa" catalog: true tags ...
- 33、VCF格式
转载:http://blog.sina.com.cn/s/blog_7110867f0101njf5.html http://www.cnblogs.com/liuhui0622/p/6246111. ...
随机推荐
- Eclipse+Maven创建webapp项目<一> (转)
Eclipse+Maven创建webapp项目<一> 1.开启eclipse,右键new——>other,如下图找到maven project 2.选择maven project,显 ...
- android-adb通用
- Apache与Tomcat整合(转)
一 Apache与Tomcat比较联系 apache支持静态页,tomcat支持动态的,比如servlet等. 一般使用apache+tomcat的话,apache只是作为一个转发,对jsp的处理是由 ...
- JSP简单的练习-用户登记表
<%@ page language="java" import="java.util.*" pageEncoding="gb2312" ...
- Cocos2d-x学习笔记(19)(TestCpp源代码分析-3)
本章主要介绍testBasic.h/cpp,这两个文件主要用于返回主场景界面. //testBasic.h #ifndef _TEST_BASIC_H_ #define _TEST_BASIC_H_ ...
- IE7,8,9兼容性处理
在IE7根据假设高度文本框中设置,则光标将不会被中心的方法如以下: 添加属性,如:style="line-height:32px\9";能够 假设一个页面有多个TAB交换的物品.而 ...
- 如何将IPhone应用软件发布到App Store的
转自:http://www.shtion.com/667.html 怎样将IPhone应用程序软件公布到应用程序商店? 2009年10月19日公布 分类: App store, iphone, 手机应 ...
- 智能家居项目(3):编译工具makefile
board文件夹中,基本的代码结构分为了src,include两个子文件夹.分别存放源码文件. #CC=arm-linux-gcc CC=gcc CFLAGS=-lpthread INCPATH=-I ...
- Android学习路径(十)如何将Action Bar堆放在布局
默认情况下,action bar出如今activity窗体的顶部,稍微降低了activity布局的总空间.假设你想隐藏或者显示action bar,在这堂用户体验的课程中,你能够通过调用hide() ...
- javascript从定义到执行 js引擎 闭包
javascript从定义到执行,JS引擎在实现层做了很多初始化工作,因此在学习JS引擎工作机制之前,我们需要引入几个相关的概念:执行环境 栈.全局对象.执行环境.变量对象.活动对象.作用域和作用域链 ...