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. ...
随机推荐
- 树莓派安装 dig命令
apt-get install dnsutils
- HDU1237 简单的计算器 【堆】+【逆波兰式】
简单的计算器 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Sub ...
- Thinkphp编辑器扩展类kindeditor用法
一, 使用前的准备. 使用前请确认你已经建立好了一个Thinkphp站点项目. 1,Keditor.class.php和JSON.class.php 是编辑器扩展类文件,将他们拷贝到你的站点项目的Th ...
- JQuery操作select checkbox radio总结
JQuery是一个非常强大的工具,所以我必须找到它最方便的方法,嘻嘻 Select CRUD: Select搜: 1.val值: $("#selectid").val(); ...
- strategy pattern
- android imageButton 透明图片
在Android有许多不规则button.例如: 这个时候,我们假设想做成不规则button的话.第一步就是搞一张边缘透明的png图片,然后用src指定到他.这个时候我们会发现,还没有达到要的效果.还 ...
- client多线程
1.多线程对象 对象可以是多线程访问,线程可以在这里分为两类: 为完成内部业务逻辑的创建Thread对象,线程需要访问对象. 使用对象的线程外部对象. 进一步假设更精细的划分.业主外螺纹成线等线,. ...
- 解决visual studio空格变成很多点号的3种方法
在用visual studio做网站时不知道按了什么快捷键,所有页面上的空格都变成了点号,就像下图那样. 要解决空格变点号的方法有两种:1.编辑->高级->查看空白2.Ctrl+E 然后按 ...
- html学习笔记二
html图片标记 <html> <head> <title>图片演示</title> </head> ----------------图片演 ...
- [cocos2dx注意事项014]一个用于cocos2dx对象智能指针模板
现在,C++有许多实现智能指针,一个更无所谓.哈. 这种智能指针是专为cocos2dx 2.2.x自定义.主要的易用性,同时必须遵循现有的cocos2dx内存管理.特殊实现这样的智能指针.无需在使用时 ...