#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. Python datetime模块的其他方法

  2. Python re.sub函数

  3. 使用C3P0和DBUtils

    1.导包 2.配置c3p0-config.xml <?xml version="1.0" encoding="UTF-8"?> <c3p0-c ...

  4. 【水滴石穿】React-Redux-Demo

    这个项目没有使用什么组件,可以理解就是个redux项目 项目地址为:https://github.com/HuPingKang/React-Redux-Demo 先看效果图 点击颜色字体颜色改变,以及 ...

  5. HTML之HTML标签

    前端的三把利器:                      (1)HTML就像一个赤裸裸的人                      (2)css就好比一件衣服                   ...

  6. UITextField 自定义clearButton背景色

    一个鸡贼的解决方案,适用于自定义clearButton的样式,直接修改背景图即可 1. 实现基于UITextField的category并添加如下方法及声明 - (void)setLightStyle ...

  7. Redis 5.0新功能介绍

    Redis 5.0 Redis5.0版是Redis产品的重大版本发布,我们先看一下它的最新特点: 新的流数据类型(Stream data type) https://redis.io/topics/s ...

  8. 在线url网址编码、解码

    >>在线url网址编码.解码<<

  9. 2015,2016 Open Source Yearbook

    https://opensource.com/yearbook/2015 The 2015 Open Source Yearbook is a community-contributed collec ...

  10. hdu 1156 && poj 2464 Brownie Points II (BIT)

    2464 -- Brownie Points II Problem - 1156 hdu分类线段树的题.题意是,给出一堆点的位置,stan和ollie玩游戏,stan通过其中一个点画垂线,ollie通 ...