CodeForces 443B Kolya and Tandem Repeat
题目:Click here
题意:给定一个字符串(只包含小写字母,并且最长200)和一个n(表示可以在给定字符串后面任意加n(<=200)个字符)。问最长的一条子串长度,子串满足前半等于后半。
分析:暴力~~~~~~
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int M = 3e5+; int k;
char str[M];
int ans, len, lenth;
bool check( int x, int y ) { // 判断字符串中[x,y]与[y+1,y-x+1]是否相同
if( x >= len ) return true;
for( int i=x; i<=y; i++ ) {
if( i+lenth >= len ) break;
if( str[i] != str[i+lenth] ) return false;
}
return true;
}
void solve() {
len = strlen( str );
ans = ;
for( int i=; i<len+k-; i++ ) {
for( int j=i; j<len+k; j++ ) {
lenth = j+-i;
if( j+lenth >= len+k ) break;
if( lenth <= ans ) continue;
if( check( i, j ) )
ans = max( ans, lenth );
if( ans == (len+k)/ ) return;
}
}
}
int main() {
while( ~scanf("%s%d", str, &k ) ) {
solve();
printf("%d\n", ans* );
}
return ;
}
CodeForces 443B 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 ...
- 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 ...
- codeforces 443 B. Kolya and Tandem Repeat 解题报告
题目链接:http://codeforces.com/contest/443/problem/B 题目意思:给出一个只有小写字母的字符串s(假设长度为len),在其后可以添加 k 个长度的字符,形成一 ...
- 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 443 B Kolya and Tandem Repeat【暴力】
题意:给出一个字符串,给出k,可以向该字符串尾部添加k个字符串,求最长的连续重复两次的子串 没有想出来= =不知道最后添加的那k个字符应该怎么处理 后来看了题解,可以先把这k个字符填成'*',再暴力枚 ...
- 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. ...
随机推荐
- Struts2 一张图片引发的bug
今天如常的打开项目开放.写了一会保存测试.在登录时出了个错误当不影响正常使用.丫的昨天还好好的.行下手上的工作 开始找bug 错误核心代码如下: 10:34:46,442 WARN OgnlValu ...
- Java和Android开发IDE---IntelliJ IDEA使用技巧(转)
以前一直使用的是Eclipse,听别人介绍说IDEA非常不错,也为了以后转Android studio铺垫下.就开始尝试用idea来开发. 这篇文章主要学习了idea的使用技巧. IDEA 全称 In ...
- HDU 3613 Best Reward(扩展KMP)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=3613 [题目大意] 一个字符串的价值定义为,当它是一个回文串的时候,价值为每个字符的价值的和,如果 ...
- 张王李相亲应用if else
package hello; public class to { public static void main(String[]args){ int a =1,b=0; int c =1,d=0; ...
- sql的强大功能(看一条sql解决的复杂业务)
一条sql语句解决的复杂业务,请往下看: 业务介绍:一个单位有多个立项(立项信息表里有单位id),每个立项可能被预警多次(预警信息表里的uuid字段的值里包含有立项id或单位id),每 ...
- POJ 1556 The Doors(计算几何+最短路)
这题就是,处理出没两个点.假设能够到达,就连一条边,推断可不能够到达,利用线段相交去推断就可以.最后求个最短路就可以 代码: #include <cstdio> #include < ...
- docker基础入门之一
一.概述 1.传统虚拟化技术: 纯软件的虚拟化是通过对于硬件层的模拟从而实现允许运行多个操作系统: 硬件辅助虚拟化需要硬件层面对于虚拟化的支持,类似Intel-VT技术等,具有更高的运行效率: 解决方 ...
- [01] Preparation - Sitecore Installment
Sitecore CMS 是一套内容管理系统商业软件,其底层平台依托于微软.net技术.由于最近的一个项目采用了这个平台,所以有机会接触到了这个产品. 虽然接触该产品已有一段时间,但总感觉对这个产品缺 ...
- Git跨平台中文乱码临时解决方案
Git 是一个非常优秀的分布式版本控制系统,最初为Linux Kernel版本管理进行量身定做.优点是,和其他版本控制系统相比,稳定,速度快,跨平台,易学易用,无需要花费成本.更多优点请点击阅读:ht ...
- BZOJ 3612: [Heoi2014]平衡( dp )
枚举Fl, 就变成一个整数划分的问题了...f(i,j) = f(i-j,j-1)+f(i-j,j)-f(i-N-1,j-1)递推.f(i,j)表示数i由j个不同的数组成,且最大不超过N的方案数 -- ...