模版——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 ...
随机推荐
- C++通配符
#include<iostream>using namespace std;bool PathernMatch(char *pat, char *str){ char *s = NULL; ...
- 如何在iPhone 显示一个 星级评分
http://blog.csdn.net/fanjunxi1990/article/details/8663914 由于项目需求,需要做一个列表,里面有各个商品的评分,就是app store里面所有a ...
- python 只导入某个对象
- JavaScript--开关思想
就是男默女泪的立flag! <!DOCTYPE html> <html lang="en"> <head> <meta charset=& ...
- hdu4176 水题
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; #def ...
- InteractiveHtmlBom 在手机上无法显示 BOM List 和装配图的问题
InteractiveHtmlBom 在手机上无法显示 BOM List 和装配图的问题 InteractiveHtmlBom 插件是一款用于 KiCad BOM 装配图生成插件. 最近新生成的 文件 ...
- 2019-8-31-dotnet-使用-System.CommandLine-写命令行程序
title author date CreateTime categories dotnet 使用 System.CommandLine 写命令行程序 lindexi 2019-08-31 16:55 ...
- 2019-3-21-win10-uwp-修改图片质量压缩图片
title author date CreateTime categories win10 uwp 修改图片质量压缩图片 lindexi 2019-03-21 15:29:20 +0800 2019- ...
- 阿里云数据库自研产品亮相国际顶级会议ICDE 推动云原生数据库成为行业标准
4月9日,澳门当地时间下午4:00-5:30,阿里云在ICDE 2019举办了主题为“云时代的数据库”的专场分享研讨会. 本次专场研讨会由阿里巴巴集团副总裁.高级研究员,阿里云智能数据库产品事业部负责 ...
- 微服务开源生态报告 No.1
从关注开源,到使用开源,再到参与开源贡献,越来越多的国内开发者通过开源技术来构建业务. 截止目前,Arthas / Dubbo / ChaosBalde / Nacos / RocketMQ / Se ...