hdu 4763 kmp ***
找AEAEA形式的字符串最长的A长度,E可以为空
只可意会,不可言传,懂kmp即可
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
#define cl(a) memset(a,0,sizeof(a))
#define ts printf("*****\n");
void kmp_pre(char x[],int m,int nextt[])
{
int i,j;
j = nextt[] = -;
i = ;
while(i < m)
{
while( - != j && x[i] != x[j] )j = nextt[j];
nextt[++i] = ++j;
}
}
char str[];
int nextt[];
bool f[];
int main()
{
#ifndef ONLINE_JUDGE
freopen("1.in","r",stdin);
#endif
int T;
scanf("%d",&T);
while(T--)
{
scanf("%s",str);
int n = strlen(str);
kmp_pre(str,n,nextt);
memset(f,false,sizeof(f));
int tmp = n;
while(tmp > )
{
if(n >= *tmp)
{
f[tmp] = true;
}
tmp = nextt[tmp];
}
int ans = ;
for(int i = ;i <n-;i++)
{
tmp = i;
while(tmp > )
{
if(f[tmp] && i >= *tmp && n >= i+tmp)
{
ans = max(ans,tmp);
break;
}
tmp = nextt[tmp];
}
}
printf("%d\n",ans);
}
return ;
}
hdu 4763 kmp ***的更多相关文章
- hdu 1686 KMP模板
// hdu 1686 KMP模板 // 没啥好说的,KMP裸题,这里是MP模板 #include <cstdio> #include <iostream> #include ...
- Cyclic Nacklace HDU 3746 KMP 循环节
Cyclic Nacklace HDU 3746 KMP 循环节 题意 给你一个字符串,然后在字符串的末尾添加最少的字符,使这个字符串经过首尾链接后是一个由循环节构成的环. 解题思路 next[len ...
- HDU 4763 (KMP算法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4763 题目大意:给定一串字符,从中找出符合“EAEBE”格式的E的最大字符数.AB可以是任意数量的任意 ...
- 2013长春网赛1005 hdu 4763 Theme Section(kmp应用)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4763 题意:给出一个字符串,问能不能在该串的前中后部找到相同的子串,输出最长的字串的长度. 分析:km ...
- (KMP灵活运用 利用Next数组 )Theme Section -- hdu -- 4763
http://acm.hdu.edu.cn/showproblem.php?pid=4763 Theme Section Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 4763 Theme Section(KMP+枚举公共前后缀)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4763 题目大意: 给你一个字符串s,存在一个子串E同时出现在前缀.中间.后缀,即EAEBE这种模式,A ...
- HDU 4763:Theme Section(KMP)
http://acm.hdu.edu.cn/showproblem.php?pid=4763 Theme Section Problem Description It's time for mus ...
- hdu 4763 Theme Section(KMP水题)
Theme Section Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
- Theme Section - HDU 4763(KMP)
题目大意:给你一个串,从这个串里面找出一个前缀后缀中间相等的串的最大长度也就是 EAEBE,每个字母都代表一个串,E出现了三次,找出最长的那个E. 分析:我们知道KMP里面保存的就是前缀和后缀的最 ...
随机推荐
- phpcms 无法显示缩略图 Call to undefined function image_type_to_extension
问题背景: 线下的phpcms项目没问题,线上的phpcms新添加的图片缩略图显示有问题,查看了一下php版本,线下是5.5的,线上的是5.1的 问题原因: 看了一下线上的错误日志,显示: PHP F ...
- 关于jquery on方法进行事件绑定触发次数指数叠加的问题
发生环境: $modal.on('click', '#search',function(e){}); 上面代码的语法是这样的: .on( events [, selector ] [, data ], ...
- SQL Server被锁的表以及解锁
select request_session_id spid,OBJECT_NAME(resource_associated_entity_id) tableName from sys ...
- POJ 2503
http://poj.org/problem?id=2503 题意就是字典翻译.这个输入输出真心恶心,要不是看discuss我肯定是解决不了,还用上了sscanf函数.... 这道题我用几种方法做. ...
- js日期、月份:日期加一天等
// 日期,在原有日期基础上,增加days天数,默认增加1天 function addDate(date, days) { if (days == undefined || days == '') { ...
- iOS 活动图 流程图
活动图 活动图和状态机图都被称为演化图,其区别和联系如下: 1.活动图:用于描述用例内部的活动或方法的流程,如果除去活动图中的并行活动描述以后,它就变成流程图. ...
- InnoDB O_DIRECT选项漫谈(一)【转】
本文来自:http://insidemysql.blog.163.com/blog/static/2028340422013671186977/ 最近和文件系统内核开发人员做技术交流,对O_DIR ...
- 【gsl】生成随机数
来自:http://hsxqwanting.blog.163.com/blog/static/16945437201301042830815/ 使用GSL生成随机数时的三个步骤: (1)gsl_ ...
- 【elasticsearch】python下的使用
有用链接: 最有用的:http://es.xiaoleilu.com/054_Query_DSL/70_Important_clauses.html 不错的博客:http://www.cnblogs. ...
- java jsp调用shell(带参数)脚本并返回值
test.jsp <%@ page language="java" import="java.util.List,java.util.ArrayList,java. ...