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. ...
随机推荐
- MyBatis的简单操作
这里将的是简单的增.删.改.查等基本操作 首先创建java项目,导入相应的依赖包,这里可以参考上一篇博客 1.添加数据 在jike.book.pojo包中,新建java类 JiKeUser.java: ...
- 2016-05-I
2016 年上半年软件设计师上午真题 1. VLIW 是( )的简称.A.复杂指令系统计算机 B.超大规模集成电路C.单指令流多数据流 D.超长指令字 2.主存与 Cache 的地址映射方式中,( ) ...
- 共享IP云主机(VPS)玩转wdcp
目前国内有不少性能还不错的共享IP VPS,但因为没有独立IP,所以环境配置起来会比较麻烦. 因为本人自己现在用的就是共享IP的vps,所以把一些配置方法分享一下,供大家参考. 首先是系统的选择,根据 ...
- springMVC 注解版
http://blog.csdn.net/liuxiit/article/details/5756115 http://blog.csdn.net/hantiannan/article/categor ...
- swift 中String常用操作
1. 字符串定义 var s = "aaaaaa" // 两个字符串均为空并等价. var emptyString = "" var anotherEmp ...
- 数据持久化之CoreData
再次回归博客园, 已经实属不易了, 面临这近期忙忙碌碌的项目开发, 虽然并不是完全的没有闲暇时间, 但是怎么说呢, 也有着各种的无奈与曲折, 面临这产品需求的不断变化和页面的不断更新, 对于一个程序员 ...
- jQuery的简单应用
时隔多日, 终于我又有时间来浏览些新知识了, 并不是偷懒什么的, 只是真的好忙, 看似闲暇的时间总是冒出一些模糊而又不得不做的事情, 今日终于我又有时间了, 可以看下jQuery了, 并根据自己的了 ...
- SQLServer中跨库复制数据
SQLServer中把某个表里的记录复制到另一个数据库的表中的操作方法. 场景 现有数据库a和数据库b,数据库a里有表table1,数据库b里有表table2.现在要把表table1里的记录复制到ta ...
- Java基础知识强化49:10个实用的但偏执的Java编程技术
1. 将String字符串放在最前面 为了防止偶发性的NullPointerException 异常,我们通常将String放置在equals()函数的左边来实现字符串比较,如下代码: // Bad ...
- 搭建LNMP架构
1. 到mysql官方下载一个源码包,尝试编译安装,编译参数可以参考我们已经安装过的mysql的编译参数.操作略,查看mysql编译参数的方法是 cat /usr/local/mysql/bin/my ...