CF 443B(253B)Kolya and Tandem Repeat
来源:互联网 发布:apache storm 源码 编辑:程序博客网 时间:2024/06/05 15:14
Kolya got string s for his birthday, the string consists of small English letters. He immediately addedk 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 couldl 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 numberk (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.
aaba2
6
aaabbbb2
6
abracadabra10
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
枚举吧,字符不长。
AC代码如下:
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#define M 100005#define ll long longusing namespace std;int main(){ char a[10005]; int k; cin>>a>>k; int l=strlen(a); int i,m,j,o,ans; m=l+k; m=m-m%2; if(k>=l) {cout<<m<<endl;return 0;}//特别记住这种情况 int max=0; for(i=0;i<l;i++)//字符的起始 { for(j=1;j<=l-i;j++)//枚举字符的长度 { for(o=i,ans=0;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;}
- CF 443B(253B)Kolya and Tandem Repeat
- CF 253B. Kolya and Tandem Repeat
- CF B. Kolya and Tandem Repeat
- Kolya and Tandem Repeat - CF#253 (Div. 2)B (443B) 哈希或水题
- Codeforces 443 B. Kolya and Tandem Repeat
- CodeForces-443B Kolya and Tandem Repeat
- CodeForces 443B Kolya and Tandem Repeat
- Codeforces 442B Kolya and Tandem Repeat(暴力)
- Kolya and Tandem Repeat
- Kolya and Tandem Repeat
- cf443B Kolya and Tandem Repeat
- CF 584B Kolya and Tanya
- B. Kolya and Tanya
- CF#324-B. Kolya and Tanya-组合数学题
- cf#324 Div.2 Problem B Kolya and Tanya
- cf B. Kolya and Tanya (快速幂_注意取模)
- Code Forces 584 B. Kolya and Tanya(快速幂)
- CodeForces - 584B Kolya and Tanya (组合数学)
- 现在公开一个DHT网络爬虫
- 闲暇时间看了下DHT网络
- boost-1.53源码编译
- C++十六进制宏的用法
- oracle中rownum详解
- CF 443B(253B)Kolya and Tandem Repeat
- winform 实现选择城市列表
- adb在安卓avd安装apk文件
- 图书管理系统
- Android中的TabHost
- Unity3d之生命槽设置
- WildFly角色分配
- 查找字符
- 点击PopupWindow之外的区域让其消失