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里面保存的就是前缀和后缀的最 ...
随机推荐
- Git打包文件
原文: http://gitbook.liuhui998.com/7_5.html 一.打包文件索引 首先, 我们来看一下打包文件索引, 基本上它只是一系列指向打包文件内位置的书签. 打包文件索引有两 ...
- 深入理解学习Git工作流
http://blog.csdn.net/hongchangfirst/article/list/3 //可以看看 http://blog.csdn.net/hongchangfirst/articl ...
- ASP.NET Web API与Rest web api
ASP.NET Web API is a framework that makes it easy to build HTTP services that reach a broad range of ...
- css 图形,非常完美
http://www.360doc.com/content/12/0327/13/8674_198243134.shtml
- MySQL中无GROUP BY直接HAVING的问题【转】
本文来自网址: http://www.penglixun.com/tech/database/having_without_groupby_in_mysql.html 今天有同学给我反应,有一张表,i ...
- ABAP 单位转换函数
CALL FUNCTION 'UNIT_CONVERSION_SIMPLE' EXPORTING input = wa_all-btg ...
- C#字符串的四舍五入
Round(Decimal) Round(Double) Round(Decimal, Int32) Round(Decimal, MidpointRounding) Round(Double, In ...
- linux下修改tomcat内存大小
转载自:http://blog.sina.com.cn/s/blog_7fb5109d0101o49a.html 1. 出现此问题的原因: 在tomcat中发布了多个webapp引用,每 ...
- MVC 使用Jquery EasyUI分页成功
先上图吧
- ios电话/密码/验证码/身份证的正则表达式
// 一 .电话号码正则表达式 -(BOOL)testPhoneNumber:(NSString *)text { NSString *regex =@"(13[0-9]|0[1-9]|0[ ...