cf443B Kolya and Tandem Repeat
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.
其实就是个很水的模拟……只要看懂题意应该就没什么问题
不过要注意k>s.length的情况
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
inline int read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int n,len,k,ans;
int main()
{
string s;
char ch[1001];
cin>>s;
scanf("%d",&k);
len=s.length();
for (int i=len;i>=1;i--)
ch[i]=s[i-1];
for (int s=1;s<=len;s++)
for (int i=1;i<=len-s+1;i++)
{
if (s-1+2*i>len+k) break;
bool mark=0;
for (int j=s+i;j<=min(len,s+i*2-1);j++)
if (ch[j-i]!=ch[j]) {mark=1;break; }
if (!mark) ans=max(i,ans);
}
if (k>len) ans=max(ans,(k+len)>>1);
printf("%d",ans*2);
}
cf443B Kolya and Tandem Repeat的更多相关文章
- 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 ...
- 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 443 B. Kolya and Tandem Repeat 解题报告
题目链接:http://codeforces.com/contest/443/problem/B 题目意思:给出一个只有小写字母的字符串s(假设长度为len),在其后可以添加 k 个长度的字符,形成一 ...
- Codeforces Round #253 (Div. 2) B - Kolya and Tandem Repeat
本题要考虑字符串本身就存在tandem, 如测试用例 aaaaaaaaabbb 3 输出结果应该是8而不是6,因为字符串本身的tanderm时最长的 故要考虑字符串本身的最大的tanderm和添加k个 ...
- Codeforces 443 B Kolya and Tandem Repeat【暴力】
题意:给出一个字符串,给出k,可以向该字符串尾部添加k个字符串,求最长的连续重复两次的子串 没有想出来= =不知道最后添加的那k个字符应该怎么处理 后来看了题解,可以先把这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. ...
随机推荐
- ACdream 1417 Numbers
pid=1417">题目链接~~> 做题感悟:比赛的时候用的广搜,然后高高兴兴的写完果断TLE .做题的时候不管什么题都要用笔画一下,模拟几组数据,这样或许就AC了(做题经验,有 ...
- Weka算法Clusterers-DBSCAN源代码分析
假设说世界上仅仅能存在一种基于密度的聚类算法的话.那么它必须是DBSCAN(Density-based spatial clustering of applications with noise).D ...
- android Settings 解析
1.Settings的主界面的实现: Settings采用了PreferenceActivity和PreferenceFragment结合的实现方式. Settings.java继承自Preferen ...
- spring技术翻译开始
从今天开始,我会坚持每天花费两个小时来翻译一本英文书(当然自己觉得绝对算得上是经典),可能我英文水平有限,但也请路过的高人予以指点. 如果有翻译的出入很大,望各位告知,本人一定更改.决定翻译的目的有两 ...
- [SVG] Simple introduce for SVG
Just like create html page, you can create a svg tag by: <?xml version="1.0" encoding=& ...
- uva 10560 - Minimum Weight(数论)
题目连接:uva 10560 - Minimum Weight 题目大意:给出n,问说至少须要多少个不同重量的砝码才干称量1~n德重量,给出所选的砝码重量,而且给出k,表示有k个重量须要用上述所选的砝 ...
- alias
1.语法:alias[别名]=[指令名称] [root@rusky /]# alias pingm="ping 127.0.0.1" [root@rusky /]# pingmP ...
- python模块基础之OS模块
OS模块简单的来说它是一个Python的系统编程的操作模块,可以处理文件和目录这些我们日常手动需要做的操作. 可以查看OS模块的帮助文档: >>> import os #导入os模块 ...
- css实现垂直居中6种方法
在一次次笔试,一次次的面试中,问到垂直居中的问题太多太多,但是我每一次回答,都好像都不能让面试官太满意,今天特意花点时间,整理一下css垂直居中问题. 1.如果是单行文本.看代码: <!DOCT ...
- javascript正则
<script type="text/javascript"> //去除两边空格,如果要去除所有空格,使用/\s*即可/ String.prototype.trim ...