题目链接:http://poj.org/problem?id=3461

减花布条 的题对比一下;

求s2中s1的个数kmp模板;

  1. #include<stdio.h>
  2. #include<iostream>
  3. #include<algorithm>
  4. #include<string.h>
  5. using namespace std;
  6.  
  7. const int N = 1e6+;
  8.  
  9. char s1[N], s2[N];
  10. int n, m, ans;
  11. int Next[N];
  12.  
  13. void GetNext()
  14. {
  15. int i = , j = -;
  16. Next[i] = j;
  17. while(i<n)
  18. {
  19. if(j==- || s2[i] == s2[j])
  20. Next[++i] = ++j;
  21. else
  22. j = Next[j];
  23. }
  24. }
  25. void kmp()
  26. {
  27. int i = , j = ;
  28. while(i<m)
  29. {
  30. if(j==- || s1[i] == s2[j])
  31. i++,j++;
  32. else
  33. j = Next[j];
  34. if(j == n)
  35. {
  36. ans++;
  37. j=Next[j];
  38. }
  39. }
  40. }
  41.  
  42. int main()
  43. {
  44. int T;
  45. scanf("%d", &T);
  46. while(T--)
  47. {
  48. scanf("%s%s", s2, s1);
  49. m = strlen(s1);
  50. n = strlen(s2);
  51. GetNext();
  52. ans = ;
  53. kmp();
  54. printf("%d\n", ans);
  55. }
  56. return ;
  57. }

Oulipo----poj3461(kmp模板)的更多相关文章

  1. poj 3461 Oulipo(KMP模板题)

    Oulipo Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 36903   Accepted: 14898 Descript ...

  2. POJ3461 KMP 模板题

    最近忙着考研复习,所以刷题少了.. 数据结构昨天重新学习了一下KMP算法,今天自己试着写了写,问题还不少,不过KMP算法总归是理解了,以前看v_JULY_v的博客,一头雾水,现在终于懂了他为什么要在算 ...

  3. HDU 1686:Oulipo(KMP模板,子串出现次数)

    Oulipo Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  4. POJ Oulipo KMP 模板题

    http://poj.org/problem?id=3461 Oulipo Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4 ...

  5. Oulipo HDU 1686 KMP模板

    题目大意:求模式串在主串中的出现次数. 题目思路:KMP模板题 #include<iostream> #include<algorithm> #include<cstri ...

  6. POJ Oulipo(KMP模板题)

    题意:找出模板在文本串中出现的次数 思路:KMP模板题 #include<cstdio> #include<cstring> #include<cmath> #in ...

  7. HDU 1686 Oulipo(kmp)

    Problem Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, w ...

  8. POJ 3461 Oulipo(——KMP算法)

    Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, without t ...

  9. POJ 3461 Oulipo 【KMP统计子串数】

    传送门:http://poj.org/problem?id=3461 Oulipo Time Limit: 1000MS   Memory Limit: 65536K Total Submission ...

  10. POJ:3461-Oulipo(KMP模板题)

    原题传送:http://poj.org/problem?id=3461 Oulipo Time Limit: 1000MS Memory Limit: 65536K Description The F ...

随机推荐

  1. la4730(并查集+树状数组)

    https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=30& ...

  2. love2d--glsl03噪声

    由于一些glsl的教程都是3d的,而love是2d的,所以之后以示例为主,我会收集 一些love的shader,分类讲解. 此文简译自love2d社区博客,这里略去作者的自我介绍. 像素着色器入门 示 ...

  3. [shell]C语言调用shell脚本接口

    Use popen if you want to run a shell command and want the parent process to be able to talk to the c ...

  4. C# 静态构造函数使用

    当我们想初始化一些静态变量的时候,就需要用到静态构造函数了.这个静态构造函数属于类,而不属于实例,就是说这个构造函数只会被执行一次,即:在创建第一个实例或引用任何静态成员之前,由.NET自动调用. 现 ...

  5. sql 使用整理

    今天使用视图查询东西,为了方便直接select * 查出来的都行全部都错乱了,看来sql 超过20个以上的字段为了效率和安全,禁止用select * -------------查一个表的所有字段的-- ...

  6. 【BZOJ】1610: [Usaco2008 Feb]Line连线游戏(几何)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1610 两种做法,一种计算几何,一种解析几何,但是计算几何的复杂度远远搞出解析集合(虽然精度最高) 计 ...

  7. ThinkPHP跳转与重定向的区别

    跳转: 浏览器认为: 当前URL请求成功, 重新请求新的URL. 浏览器会 记录当前的URL 和 新的URL 在请求历史记录中. 回退, 是可以回退到, 当前的URL上的. (无论 success, ...

  8. ArcGIS -- ArcSDE Lock request conflicts with an established lock

    1.查询下列表是否有数据 select * from sde.state_locks; select * from sde.object_locks; select * from sde.layer_ ...

  9. shell脚本学习总结02--数组

    bash同时支持普通数组个关联数组,普通数组只能使用整数作为数组的索引,关联数组可以使用字符串作为数组的索引. 数组的定义方法: 在单行中使用一列值定义一个数组 [root@new ~]# array ...

  10. m2014_c->c语言容器类工具列

    转自:http://www.cnblogs.com/sniperHW/category/374086.html cocos2dx内存管理 摘要: cocos2dx基于引用计数管理内存,所有继承自CCO ...