HDU 1686 Oulipo kmp模板
来源:互联网 发布:广州经济开发区知乎 编辑:程序博客网 时间:2024/06/05 02:03
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1686
题意:给一个模式串,一个目标串,问目标串中有几个模式串
思路:kmp模板题,留个模板。。。
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int N = 10010;char s1[N], s2[N*100];int nt[N];void getnt(){ int i = 0, j = -1; nt[0] = -1; while(s1[i]) { if(j == -1 || s1[i] == s1[j]) { i++, j++; if(s1[i] != s1[j]) nt[i] = j; else nt[i] = nt[j]; } else j = nt[j]; }}int kmp(){ int i = 0, j = 0, cnt = 0; getnt(); while(s2[i]) { if(j == -1 || s2[i] == s1[j]) i++, j++; else j = nt[j]; if(j != -1 && ! s1[j]) cnt++, j = nt[j]; } return cnt;}int main(){ int t; scanf("%d", &t); while(t--) { scanf(" %s %s", s1, s2); printf("%d\n", kmp()); } return 0;}
0 0
- HDU 1686 Oulipo kmp模板
- hdu 1686 Oulipo (KMP模板)
- hdu 1686 Oulipo -- (KMP模板题)
- HDU 1686Oulipo (kmp模板题)
- HDU-1686 Oulipo(kmp模板题)
- HDU 1686 Oulipo【KMP模板题】
- HDU 1686 Oulipo (kmp)
- hdu 1686 kmp Oulipo
- KMP hdu-1686-Oulipo
- Hdu 1686 Oulipo[kmp]
- hdu 1686 Oulipo(KMP)
- HDU-1686-Oulipo(KMP)
- hdu 1686 Oulipo(KMP)
- hdu 1686 Oulipo(KMP)
- HDU 1686 Oulipo (KMP)
- HDU 1686 Oulipo(KMP)
- HDU - 1686 Oulipo (KMP)
- HDU 1686 Oulipo(KMP)
- android中的反射机制
- SAP MD04详解
- hdoj2035 人见人爱A^B(快速幂+同余定理)
- Java中的hashcode方法
- Valid Anagram
- HDU 1686 Oulipo kmp模板
- 1019. General Palindromic Number (20)
- iOS编码规范
- OpenCV | 滤波
- 一个操作系统的实现--从loader到内核和扩充内核的错误兼参考指令
- 通过异步任务将一张由网络得来图片显示出来
- Gradle学习
- C#中的垃圾回收
- NSCondition的用法