找AEAEA形式的字符串最长的A长度,E可以为空

只可意会,不可言传,懂kmp即可

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <iostream>
  4. #include <algorithm>
  5. #include <vector>
  6. #include <queue>
  7. #include <set>
  8. #include <map>
  9. #include <string>
  10. #include <math.h>
  11. #include <stdlib.h>
  12. #include <time.h>
  13. using namespace std;
  14. #define cl(a) memset(a,0,sizeof(a))
  15. #define ts printf("*****\n");
  16. void kmp_pre(char x[],int m,int nextt[])
  17. {
  18. int i,j;
  19. j = nextt[] = -;
  20. i = ;
  21. while(i < m)
  22. {
  23. while( - != j && x[i] != x[j] )j = nextt[j];
  24. nextt[++i] = ++j;
  25. }
  26. }
  27. char str[];
  28. int nextt[];
  29. bool f[];
  30. int main()
  31. {
  32. #ifndef ONLINE_JUDGE
  33. freopen("1.in","r",stdin);
  34. #endif
  35. int T;
  36. scanf("%d",&T);
  37. while(T--)
  38. {
  39. scanf("%s",str);
  40. int n = strlen(str);
  41. kmp_pre(str,n,nextt);
  42. memset(f,false,sizeof(f));
  43. int tmp = n;
  44. while(tmp > )
  45. {
  46. if(n >= *tmp)
  47. {
  48. f[tmp] = true;
  49. }
  50. tmp = nextt[tmp];
  51. }
  52. int ans = ;
  53. for(int i = ;i <n-;i++)
  54. {
  55. tmp = i;
  56. while(tmp > )
  57. {
  58. if(f[tmp] && i >= *tmp && n >= i+tmp)
  59. {
  60. ans = max(ans,tmp);
  61. break;
  62. }
  63. tmp = nextt[tmp];
  64. }
  65. }
  66. printf("%d\n",ans);
  67. }
  68. return ;
  69. }

hdu 4763 kmp ***的更多相关文章

  1. hdu 1686 KMP模板

    // hdu 1686 KMP模板 // 没啥好说的,KMP裸题,这里是MP模板 #include <cstdio> #include <iostream> #include ...

  2. Cyclic Nacklace HDU 3746 KMP 循环节

    Cyclic Nacklace HDU 3746 KMP 循环节 题意 给你一个字符串,然后在字符串的末尾添加最少的字符,使这个字符串经过首尾链接后是一个由循环节构成的环. 解题思路 next[len ...

  3. HDU 4763 (KMP算法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4763 题目大意:给定一串字符,从中找出符合“EAEBE”格式的E的最大字符数.AB可以是任意数量的任意 ...

  4. 2013长春网赛1005 hdu 4763 Theme Section(kmp应用)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4763 题意:给出一个字符串,问能不能在该串的前中后部找到相同的子串,输出最长的字串的长度. 分析:km ...

  5. (KMP灵活运用 利用Next数组 )Theme Section -- hdu -- 4763

    http://acm.hdu.edu.cn/showproblem.php?pid=4763 Theme Section Time Limit: 2000/1000 MS (Java/Others)  ...

  6. HDU 4763 Theme Section(KMP+枚举公共前后缀)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4763 题目大意: 给你一个字符串s,存在一个子串E同时出现在前缀.中间.后缀,即EAEBE这种模式,A ...

  7. HDU 4763:Theme Section(KMP)

    http://acm.hdu.edu.cn/showproblem.php?pid=4763 Theme Section Problem Description   It's time for mus ...

  8. hdu 4763 Theme Section(KMP水题)

    Theme Section Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) To ...

  9. Theme Section - HDU 4763(KMP)

    题目大意:给你一个串,从这个串里面找出一个前缀后缀中间相等的串的最大长度也就是 EAEBE,每个字母都代表一个串,E出现了三次,找出最长的那个E.   分析:我们知道KMP里面保存的就是前缀和后缀的最 ...

随机推荐

  1. Git打包文件

    原文: http://gitbook.liuhui998.com/7_5.html 一.打包文件索引 首先, 我们来看一下打包文件索引, 基本上它只是一系列指向打包文件内位置的书签. 打包文件索引有两 ...

  2. 深入理解学习Git工作流

    http://blog.csdn.net/hongchangfirst/article/list/3 //可以看看 http://blog.csdn.net/hongchangfirst/articl ...

  3. 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 ...

  4. css 图形,非常完美

    http://www.360doc.com/content/12/0327/13/8674_198243134.shtml

  5. MySQL中无GROUP BY直接HAVING的问题【转】

    本文来自网址: http://www.penglixun.com/tech/database/having_without_groupby_in_mysql.html 今天有同学给我反应,有一张表,i ...

  6. ABAP 单位转换函数

    CALL FUNCTION 'UNIT_CONVERSION_SIMPLE'         EXPORTING           input                = wa_all-btg ...

  7. C#字符串的四舍五入

    Round(Decimal) Round(Double) Round(Decimal, Int32) Round(Decimal, MidpointRounding) Round(Double, In ...

  8. linux下修改tomcat内存大小

    转载自:http://blog.sina.com.cn/s/blog_7fb5109d0101o49a.html 1.  出现此问题的原因:       在tomcat中发布了多个webapp引用,每 ...

  9. MVC 使用Jquery EasyUI分页成功

    先上图吧

  10. ios电话/密码/验证码/身份证的正则表达式

    // 一 .电话号码正则表达式 -(BOOL)testPhoneNumber:(NSString *)text { NSString *regex =@"(13[0-9]|0[1-9]|0[ ...