模版——KMP
#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的更多相关文章
- 马拉车——模版+KMP——模版
void Manacher(){ ;t[i];++i,len+=){ s[i<<]='#'; |]=t[i]-'A'+'a'; |]=t[i]; } s[len++]='#'; ,pos= ...
- KMP模版 && KMP求子串在主串出现的次数模版
求取出现的次数 : #include<bits/stdc++.h> ; char mo[maxn], str[maxn];///mo为模式串.str为主串 int next[maxn]; ...
- Kuangbin 带你飞 KMP扩展KMP Manacher
首先是几份模版 KMP void kmp_pre(char x[],int m,int fail[]) { int i,j; j = fail[] = -; i = ; while (i < m ...
- 两种KMP题+KMP模版整理
最近稍微看了下KMP,不是很懂他们大神的A题姿势,但是模版总该还是要去学的. 其中next数组的求法有两处区别. 第一种:求主串中模式串的个数.HDU2087 剪花布条和HDU4847 Wow! Su ...
- KMP模版
#include<iostream> #include<cstdio> #include<cstring> using namespace std; ]; void ...
- HDU 5918 SequenceI (2016 CCPC长春站 KMP模版变形)
这个题目的数据应该是比较弱的,赛场上的时候我们暴力也过了,而且我的kmp居然比暴力还要慢-- 这个变形并不难,跳着选数,把漏掉的位置补上就可以了. 代码如下: #include<iostream ...
- 【poj 1961】Period(字符串--KMP 模版题)
题意:给你一个字符串,求这个字符串到第 i 个字符为止的重复子串的个数. 解法:判断重复子串的语句很重要!!if (p && i%(i-p)==0) printf("%d % ...
- KMP的模版实现(以hdu1711为例)
贴代码,觉得带template的有一些大材小用……不过还是按自己风格写吧! /************************************************************* ...
- 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 ...
随机推荐
- NOIP模拟 17.8.18
NOIP模拟17.8.18 A.小菜一碟的背包[题目描述]Blice和阿强巴是好朋友但萌萌哒Blice不擅长数学,所以阿强巴给了她一些奶牛做练习阿强巴有 n头奶牛,每头奶牛每天可以产一定量的奶,同时也 ...
- react-native-login-redux
项目地址如下 https://github.com/agunbuhori/react-native-login-redux 先看页面 ```js // 还有中英文切换 //src/global.js ...
- 阿里开源自用 OpenJDK 版本,Java 社区迎来中国力量
阿里开源自用 OpenJDK 版本,Java 社区迎来中国力量 3 月 21 日,阿里巴巴将宣布开源 Alibaba Dragonwell.届时,开发者可通过阿里云开发者中心及 Github 社区下载 ...
- 使用 Apachetop 实时监测web服务器运行状况
转自 http://42.96.169.71/blog/2013/01/26/shi-yong-apachetop-shi-shi-jian-ce-webfu-wu-qi-yun-xing-zhuan ...
- ESP8266 支持浮点运算吗?
ESP8266 支持浮点运算吗? 可以说支持,也可以说不支持. 说不支持的原因是因为 ESP8266 内部没有 FPU,无法使用硬件计算. 说支持的意思是可以使用软件进行浮点运算,但是会很慢很慢,如果 ...
- python 通过.pth文件修改搜索路径
- jQuery之父:坚持每天都要写代码
关于作者:John Resig, jQuery之父,同时也是Pro Javascript Techniques和Secrets of the JavaScript Ninja的作者.他目前主持 Kha ...
- MUI - myStorage在ios safari无痕浏览模式下的解决方案
myStorage在ios safari无痕浏览模式下的解决方案 今天看到了这个帖子LocalStorage 在 Private Browsing 下的一个限制, 吓尿了,如果用户开启了无痕浏览,ap ...
- css面试题总结(转)
转自此网页http://www.cnblogs.com/YangqinCao/p/5721810.html. 1.两栏布局,左边栏宽度固定,适应父元素高度变化 首先分析两栏布局, 两栏布局两种常见方法 ...
- JavaScript —— 常用数据类型隐式转换
公用方法: let checkType = (data) => { if(data){ console.log(true); }else{ console.log(false); } } 一.字 ...