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. ...
随机推荐
- hdu1372 dfs搜索之国际象棋的马
原题地址 题意 一个8x8的国际象棋棋盘,你有一个棋子"马".算出棋子"马"从某一格到还有一格子的最少步数. 与普通dfs不同的是,你能走的路线不是上下左右,四 ...
- 牟大哥:《App自我促销》连载2
直立人迁移走
[谋哥每天一干货,第六十九篇] 前篇说到声音在远古时代.是一个奇妙的东西,它可以非常快地把信息传播到其它地方,突破了短距离. 然而能人的后代直立人学会了直立行走,他们開始走出非洲,到达遥远的中东.中国 ...
- SQL 编码标准
1. 你必须从别名表,易于使用的表,该表列 实例 select owner,object_id,name from a,b where a.id=b.id; 假设是不正确的别名表.我知道你是怎么访问表 ...
- .net Quartz 服务 作业调度
.net项目中使用Quartz (1)在web.config中进行相关配置 <configSections> <section name="quartz" t ...
- android看不见main函数怎么办?程序异常了,能够不提示“xxx软件停止执行”吗?
今天遇到了这个问题,分享一下解决方式. android没有main 函数,自然也就不存在main里面加入异常处理来实现全局异常捕获的方案.那android程序有全局异常补货的解决方式吗? 答案是有的: ...
- 构建安全的Xml Web Service系列之wse之证书存储位置
原文:构建安全的Xml Web Service系列之wse之证书存储位置 我们在前几天对xml web service的安全性提出了一些建议,大家可以通过以下地址访问: 构建安全的Xml Web Se ...
- TI C66x DSP 系统events及其应用 - 5.8(ISTP)
中断服务表指针ISTP(Interrupt Service Table Pointer)位置寄存器用于定位的中断服务例程,那ISTP去哪里找要运行的程序,ISTP(当中的ISTB字段)就是指向IST表 ...
- 【C语言探索之旅】 第三部分第一课:SDL开发游戏之安装SDL
内容简介 1.课程大纲 2.第三部分第一课: SDL开发游戏之安装SDL 3.第三部分第二课预告: SDL开发游戏之创建窗口和画布 课程大纲 我们的课程分为四大部分,每一个部分结束后都会有练习题,并会 ...
- Visual Studio 使用及调试必知必会
原文:Visual Studio 使用及调试必知必会 一:C# CODING 技巧 1:TODO 然后 CTRL + W + T,打开任务列表,选中 Comments,就会显示所有待做的任务 2: ...
- C#使用xpath找到一个节点
Xpath这是非常强大.但对比是一个更复杂的技术,希望上面去博客园特别想看看一些专业职位.下面是一些简单Xpath的语法和示例,给你参考 <?xml version="1.0" ...