代码来源:TYUT_YancyKahn

AC的C++语言程序如下:

#include <iostream>
#include <cstdio>
#include <cstring>using namespace std;const int MAXN = 10000;
const int MAXM = 1000000;int next[MAXN];void getNext(string pattern, int len)
{int k = -1;next[0] = -1;for(int i = 1; i < len; ++i){while(k > -1 && pattern[k + 1] != pattern[i]) k = next[k];if(pattern[k + 1] == pattern[i]) k++;next[i] = k;}
}int kmp(string pattern, int plen, string target, int tlen)
{int k = -1;int cnt = 0;for(int i = 0; i < tlen; ++i){while(k > -1 && pattern[k + 1] != target[i]) k = next[k];if(pattern[k + 1] == target[i]) k ++;if(k == plen - 1) cnt ++, k = next[k];}return cnt;
}int main()
{ios::sync_with_stdio(false);cin.tie(0);int t;string pattern, target;cin >> t;while(t--){cin>> pattern >> target ;getNext(pattern, pattern.size());int m = kmp(pattern, pattern.size(), target, target.size());cout << m << endl;}
}

POJ3461 HDU1686 Oulipo题解相关推荐

  1. HDU1686——Oulipo

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

  2. 【POJ3461】Oulipo(字符串Hash)

    problem 给定两个字符串s1,s2,求s1在s2中出现了多少次(可重叠). len(s1) < 1e4, len(s2) < 1e6. solution 字符串Hash 介绍: 字符 ...

  3. ICPC程序设计题解书籍系列之五:吴永辉:《数据结构编程实验》(第2版)

    第1章 简单计算 UVALive2362 POJ1004 HDU1064 ZOJ1048 Financial Management[数学+水题] - 海岛Blog - CSDN博客 POJ1552 H ...

  4. MUV LUV UNLIMITED(ccpc 秦皇岛2019)

    MUV LUV UNLIMITED(ccpc 秦皇岛2019) 题目描述 There are few entertainments in United Nations 11th Force, Paci ...

  5. POJ3461 Oulipo ——KMP算法——Pku3461

    建议大家学一学比较巧妙的KMP算法吧,很有意思.推荐个题目:POJ3167 Cow Patterns 题解我会发在本博里. 这个KMP就木有什么好说的了吧,大家找百度百科学一下就可以了~ CODE P ...

  6. Oulipo(POJ-3461)

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

  7. Oulipo(欧力波)(经典kmp模板题) HDU-1686

    题目:Oulipo(欧力波) 中文大意 The French author Georges Perec (1936�C1982) once wrote a book, La disparition, ...

  8. HDU - 1686 Oulipo

    https://vjudge.net/problem/HDU-1686 HDU - 1686 Oulipo 题目 分析 AC代码 题目 The French author Georges Perec ...

  9. Oulipo (KMP算法)

    Oulipo (KMP算法) 题目链接:HDU-1686 题目: Oulipo Problem Description The French author Georges Perec (1936–19 ...

最新文章

  1. android java.lang.IllegalArgumentException: Comparison method violates its general contract! 问题
  2. anaconda: import numpy报错:ImportError: DLL load failed: 找不到指定的模块。
  3. golang 可变参 不定参 函数 简介
  4. php 匿名方法,PHP基于Closure类创建匿名函数的方法详解
  5. 官方版下载_药店大学app官方版下载
  6. Django模版(三)
  7. oa 中会议推送 实现_揭秘“OA与ERP高端融合方案”三大亮点
  8. 怎样下载C/C++的免费、开源且跨平台IDE——Code::Blocks
  9. 华为首款鸿蒙设备正式入网,华为首款鸿蒙设备正式入网:麒麟9000+挖孔全面屏,价格感人!...
  10. USB连接TF卡 SD卡硬件电路
  11. 欧拉定理(洛谷-P5091)(十进制快速幂实现)
  12. 中livechart显示大数据_Kaggle 大数据竞赛中的Tricks总结
  13. HtmlNinja-图片预加载以及图片元素img的complete属性
  14. 【后缀数组】bzoj2217 Secretary
  15. Python3.6 用Django连接MySQL
  16. mysql 游标动态传参数_Mysql 游标施用动态变量
  17. 锂离子电池容量计量之库仑计法
  18. Python解线性方程组的直接法(5)————平方根法求解线性方程组
  19. B站秋招编程题:扭蛋机
  20. c语言中at指令的比较,AT指令(中文详解版)(二)

热门文章

  1. PHP中include和require的区别详解
  2. java中的jni_JAVA中JNI的简单使用
  3. android期末大作业_关于大学期末的一点碎碎念
  4. onepill服务端
  5. Doris之DataX doriswriter
  6. mysql select in 排序_MySQL数据库之Mysql select in 按id排序实现方法
  7. linux端口扫描脚本ip段,shell脚本结合iptables防端口扫描的实现
  8. Object类的使用,包装类的使用
  9. 谷歌搜索363搜索引擎入口_SEO谷歌搜索引擎优化到底有啥好?
  10. 剑指offer面试题27. 二叉树的镜像(递归)