Oulipo POJ - 3461 KMP

Posted MeowMeowMeow

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Oulipo POJ - 3461 KMP相关的知识,希望对你有一定的参考价值。

//以前没分类过 现在该分类一下了
#include <iostream> #include <algorithm> #include <stdio.h> #include <set> #include <queue> #include <cstring> #include <string> #include <limits.h> #include <string.h> #include <vector> #include <map> #define LL long long #define INF 2100000000 #define fi first #define se second #define lowbit(x) (x&(-x)) #define eps 5e-7 using namespace std; const int maxn=(int)1e6 +10; const int maxm=(int)1e4+10; const LL MOD=(LL)1e9+7; int next1[maxm]; void kmppre(char x[]) { int i,j; j=next1[0]=-1; //next[i]表示在第i个字符失配后, //模式串中0->next[i]处仍为匹配状态 i=0; while(x[i]) { while(j!=-1&&x[i]!=x[j]) j=next1[j]; next1[++i]=++j; } } int kmpcount(char x[],char y[]){ int i,j,ans=0; kmppre(x); i=j=0; while(y[i]){ while(j!=-1&&y[i]!=x[j])j=next1[j]; i++;j++; if(!x[j]){ ans++;j=next1[j]; } } return ans; } char s1[maxm],s2[maxn]; int main() { #ifdef shuaishuai freopen("C:\\Users\\hasee\\Desktop\\a.txt","r",stdin); //freopen("C:\\Users\\hasee\\Desktop\\b.txt","w",stdout); #endif int t; scanf("%d\n", &t); while(t--){ gets(s1);gets(s2); printf("%d\n",kmpcount(s1,s2)); } return 0; }

 

以上是关于Oulipo POJ - 3461 KMP的主要内容,如果未能解决你的问题,请参考以下文章

poj 3461 - Oulipo 经典kmp算法问题

POJ 3461 Oulipo KMP算法题解

poj 3461 Oulipo(KMP)

POJ3461 Oulipo[KMP]

POJ 题目3461 Oulipo(KMP)

POJ3461 Oulipo[KMP]学习笔记