HDU 1686 Oulipo
来源:互联网 发布:杭州java平均薪资 编辑:程序博客网 时间:2024/06/04 19:05
题目链接
题意:问一个主串包含多少个模式串
分析:kmp模板题
#include<cstdio>#include<algorithm>#include<cstring>#define MAX_P 10005#define MAX_T 1000005using namespace std;char P[MAX_P];char T[MAX_T];int NEXT[MAX_P];int cnt;void makeNext(void){ int q,k; int m=strlen(P); NEXT[0]=0; for(q=1,k=0;q<m;q++) { while(k>0&&P[q]!=P[k]) k=NEXT[k-1]; if(P[q]==P[k]) k++; NEXT[q]=k; } return ;}int kmp(void){ int len_t=strlen(T); int len_p=strlen(P); makeNext(); for(int i=0,q=0;i<len_t;i++) { while(q>0&&P[q]!=T[i]) q=NEXT[q-1]; if(P[q]==T[i]) q++; if(q==len_p) cnt++; } return cnt;}int main(void){ int t; scanf("%d",&t); while(t--) { scanf("%*c%[^\n]",P); scanf("%*c%[^\n]",T); cnt=0; int ans=kmp(); printf("%d\n",ans); } return 0;}
0 0
- HDU 1686 Oulipo (kmp)
- hdu 1686 Oulipo
- hdu 1686 Oulipo
- hdu 1686 Oulipo
- hdu 1686 kmp Oulipo
- hdu 1686 Oulipo
- KMP hdu-1686-Oulipo
- HDU 1686 Oulipo
- Hdu 1686 Oulipo[kmp]
- hdu 1686 Oulipo(KMP)
- hdu 1686 Oulipo
- HDU-1686-Oulipo(KMP)
- hdu 1686 Oulipo(KMP)
- hdu 1686 Oulipo(KMP)
- HDU - 1686 Oulipo
- HDU 1686 Oulipo (KMP)
- HDU 1686 Oulipo(KMP)
- HDU 1686 Oulipo - KID
- 【杭电oj2647】Reward
- Leetcode之路 258. Add Digits
- SiteMesh
- eclipse下maven项目开发编译
- 向量vector理解
- HDU 1686 Oulipo
- 五大常用算法之三:贪心算法(转)
- Android:极光推送集成注意要点——解决:Get sdk version fail![获取sdk版本失败!]解决方案
- [编程题]由异或门引出的几道数组的算法题
- TreeSet&NavigableMap&NavigableSet源码解析 给jdk写注释系列之jdk1.6容器(8)
- TensorFlow学习笔记(三):Tutorial第二个例子-深入MNIST-卷积神经网络
- Python基础教程1-3章笔记
- 杭电-4857 逃生(拓扑排序+优先队列)
- 邻接表(链表)存图