cf 443B Kolya and Tandem Repeat
2015-07-29 00:07
381 查看
B. Kolya and Tandem Repeat
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
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.
Input
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.
Output
Print a single number — the maximum length of the tandem repeat that could have occurred in the new string.
Sample test(s)
input
output
input
output
input
output
Note
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.
大力出奇迹2333
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
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.
Input
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.
Output
Print a single number — the maximum length of the tandem repeat that could have occurred in the new string.
Sample test(s)
input
aaba 2
output
6
input
aaabbbb 2
output
6
input
abracadabra 10
output
20
Note
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.
大力出奇迹2333
/************************************************************************* > File Name: code/2015summer/#3/A.cpp > Author: 111qqz > Email: rkz2013@126.com > Created Time: 2015年07月28日 星期二 12时27分08秒 ************************************************************************/ #include<iostream> #include<iomanip> #include<cstdio> #include<algorithm> #include<cmath> #include<cstring> #include<string> #include<map> #include<set> #include<queue> #include<vector> #include<stack> #define y0 abc111qqz #define y1 hust111qqz #define yn hez111qqz #define j1 cute111qqz #define tm crazy111qqz #define lr dying111qqz using namespace std; #define REP(i, n) for (int i=0;i<int(n);++i) typedef long long LL; typedef unsigned long long ULL; const int N=1E4+5; char a ; int k; int main() { cin>>a>>k; int l=strlen(a); int m,ans; m=l+k; if (m%2==1) m--; if(k>=l) { cout<<m<<endl; return 0; } int max=0; for(int i = 0 ; i < l ; i++) { for(int j = 1 ; j <= l-i;j++) { ans = 0; for(int o = i ; o < i+j ; o++) { if(o+j>=l&&o+j<l+k) ans++; else if(a[o]==a[o+j]) ans++; } if(ans==j&&2*ans>max) max=2*ans; } } cout<<max<<endl; return 0; }
相关文章推荐
- HDU 1087
- poj 2135 有流量限制的最小费用最大流
- Android中滑屏实现----手把手教你如何实现触摸滑屏以及Scroller类详解
- 在matlab中进行地理坐标和像素坐标的相互转换
- 点对点 客户端-服务器 聊天程序
- hdu 5035 Delivery(期望)
- PAT乙级 1015. 德才论
- C++对象模型——关键词所带来的差异(第一章)
- 磁盘读写
- Ext store中使用回调函数
- linux下解压iso文件
- Android开机键失灵启动手机的解决办法
- Java程序员面试题
- Android开机键失灵启动手机的解决办法
- linux下解压iso文件
- AutoLayout五、使用Masonry完成UITableViewCell的自适应高度
- 新博客地址
- haproxy 网站访问代理功能
- 如何使用CSS3画出一个叮当猫
- java实现上传和下载工具类