#include <iostream>
#include <cstdio>
#include <cstring> const int maxn = ;
int f[maxn];
char P[maxn];
char T[maxn];
void getfail(char* P, int *f) {
f[] = f[] = ;
int n = strlen(P);
for(int i = ; i < n; i++) {
int j = f[i];
while(j && P[i] != P[j]) j = f[j];
f[i+] = P[i] == P[j] ? j+ : ;
}
} void KMP(char* T, char* P, int* f) {
int n = strlen(T), m = strlen(P);
getfail(P, f);
int j = ;
for(int i = ; i < n; i++) {
while(j && T[i] != P[j]) j = f[j];
if(T[i] == P[j]) j++;
if(j == m) {
printf("%d\n", i-m+);
j = ;
}
}
}

模版——KMP的更多相关文章

  1. 马拉车——模版+KMP——模版

    void Manacher(){ ;t[i];++i,len+=){ s[i<<]='#'; |]=t[i]-'A'+'a'; |]=t[i]; } s[len++]='#'; ,pos= ...

  2. KMP模版 && KMP求子串在主串出现的次数模版

    求取出现的次数 :  #include<bits/stdc++.h> ; char mo[maxn], str[maxn];///mo为模式串.str为主串 int next[maxn]; ...

  3. Kuangbin 带你飞 KMP扩展KMP Manacher

    首先是几份模版 KMP void kmp_pre(char x[],int m,int fail[]) { int i,j; j = fail[] = -; i = ; while (i < m ...

  4. 两种KMP题+KMP模版整理

    最近稍微看了下KMP,不是很懂他们大神的A题姿势,但是模版总该还是要去学的. 其中next数组的求法有两处区别. 第一种:求主串中模式串的个数.HDU2087 剪花布条和HDU4847 Wow! Su ...

  5. KMP模版

    #include<iostream> #include<cstdio> #include<cstring> using namespace std; ]; void ...

  6. HDU 5918 SequenceI (2016 CCPC长春站 KMP模版变形)

    这个题目的数据应该是比较弱的,赛场上的时候我们暴力也过了,而且我的kmp居然比暴力还要慢-- 这个变形并不难,跳着选数,把漏掉的位置补上就可以了. 代码如下: #include<iostream ...

  7. 【poj 1961】Period(字符串--KMP 模版题)

    题意:给你一个字符串,求这个字符串到第 i 个字符为止的重复子串的个数. 解法:判断重复子串的语句很重要!!if (p && i%(i-p)==0) printf("%d % ...

  8. KMP的模版实现(以hdu1711为例)

    贴代码,觉得带template的有一些大材小用……不过还是按自己风格写吧! /************************************************************* ...

  9. poj 2752 Seek the Name, Seek the Fame (KMP纯模版)

    Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 13840   Ac ...

随机推荐

  1. JDBC的事务处理 JDBC事务处理 JDBC教程

    JDBC的事务基本知识 事务的定义:一个事务是由一条或多条对数据库操作的sql语句所组成的一个不可分割的工作单元,只有当事务中的所有操作都正常执行后,整个事务才会提交给数据库. 结束事务的操作:com ...

  2. 【转】基于OLSR路由协议实现Ad-Hoc组网

    一.软件包的安装 1. olsrd软件包的安装 libpthread_0.9.33.2-1_ar71xx.ipk olsrd_0.6.6.2-4_ar71xx.ipk 2. luci的安装 olsrd ...

  3. Sentinel 1.5.0 正式发布,引入 Reactive 支持

    近日,流控降级组件 Sentinel 的又一个里程碑版本 1.5.0 正式发布. 该版本引入 Reactive 的支持,并提供多项新特性与改进.从 1.5.0 版本开始,Sentinel 仅支持 JD ...

  4. KDD2016,Accepted Papers

    RESEARCH TRACK PAPERS - ORAL Title & Authors NetCycle: Collective Evolution Inference in Heterog ...

  5. Directx11教程(31) 纹理映射(1)

    原文:Directx11教程(31) 纹理映射(1)         在前面的例子中,我们要么是直接给顶点赋颜色值,要么是在顶点属性中设置Diffuse和Specular系数,从而根据光照参数计算得到 ...

  6. @spoj - ADAMOLD@ Ada and Mold

    目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定一个长度为 N 的序列 A,将其划分成 K + 1 段,划分 ...

  7. VS中,卸载,移除,删除项目的区别

    不说话,上图.

  8. SqlSugar 笔记

    分组: 日期分组一: var result = await temp .GroupBy("date_format(Day,'%Y-%m')") .Select(s => ne ...

  9. SDWebImage源码解析之SDWebImageManager的注解

    http://www.cocoachina.com/ios/20150612/12118.html 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ...

  10. 7-3三个模块 hashlib ,logging,configparser和序列化

    一 hashlib 主要用于字符串加密 1 import hashlib md5obj=hashlib.md5() # 实例化一个md5摘要算法的对象 md5obj.update('alex3714' ...