POJ 3461 (KMP)
来源:互联网 发布:电机选型软件 编辑:程序博客网 时间:2024/05/22 10:46
题意:在S串里找T串出现多少次?
题解:直接上KMP模板就可以了
#include<iostream>#include<cstdio>#include<cstring>using namespace std;int ans;#define N 1000000+5char s1[N],s2[N];int fail[N];void getfail(char *p,int *f){int m=strlen(p);f[0]=0;f[1]=0;for(int i=1;i<m;i++){int j=f[i];while(j&&p[i]!=p[j])j=f[j];f[i+1]=p[i]==p[j]?j+1:0;}}void find(char *t,char *p,int *f){int n=strlen(t),m=strlen(p);getfail(p,f);int j=0;for(int i=0;i<n;i++){while(j&&p[j]!=t[i])j=f[j];if(p[j]==t[i])j++;if(j==m)ans++;}}int main(){#ifdef CDZSCfreopen("i.txt","r",stdin);#endifint tt;scanf("%d",&tt);while(tt--){scanf("%s%s",s1,s2);ans=0;find(s2,s1,fail);printf("%d\n",ans);}return 0;}
0 0
- POJ 3461 (KMP)
- POJ 3461 (kmp)
- POJ 3461 - Oulipo(KMP)
- POJ-3461 Oulipo(KMP)
- Poj 3461 Oulipo (KMP)
- POJ---3461-Oulipo(KMP)
- POJ 3461 Oulipo(KMP)
- POJ 3461 Oulipo(KMP)
- 【POJ 3461】Oulipo(kmp)
- poj 3461 Oulipo(KMP)
- poj 3461 Oulipo(KMP)
- poj 3461:Oulipo(KMP模版)
- POJ 3461 Oulipo(简单KMP)
- poj 3461 Oulipo(kmp 模板题)
- Poj 3461 Oulipo(KMP算法)
- POJ 3461 Oulipo(KMP模板)
- POJ 3461 Oulipo (KMP算法)
- kmp算法(POJ 3461 Oulipo)
- hdu acm 1115 Lifting the Stone(多边形重心)
- JSP实现文件上传【ie下有效】
- [maya学习笔记(2)] 物体的基本操作
- Activity—生命周期方法
- bzoj 3994
- POJ 3461 (KMP)
- 给已经建立的Xcode工程添加git版本控制
- Codeforces Round #256 (Div. 2) C. Painting Fence (DFS)
- Android开发者必知的5个开源库
- hdu 4389 数位DP 模板化代码 结合记忆化搜索优化
- junit
- 1
- KMP模板
- Windows10强力卸载OneDrive