hdu 1711 KMP模板题
来源:互联网 发布:教室楼图纸软件 编辑:程序博客网 时间:2024/04/30 04:14
//hdu 1711 KMP模板题//贴个KMP模板吧~~~#include <cstdio>#include <cstring>#include <algorithm>#include <iostream>using namespace std;const int MAX_N = 1000008;const int MAX_M = 10008;int T[MAX_N];int p[MAX_M];int f[MAX_M];int n,m;void getfail(){f[0] = f[1] = 0;for (int i=1;i<m;i++){int j = f[i];while(j && p[j]!=p[i])j = f[j];f[i+1] = (p[i]==p[j]) ? j+1 : 0;}}int cmp(){int j = 0;for (int i=0;i<n;i++){while(j && T[i] != p[j])j = f[j];if (T[i] == p[j])j++;if (j==m){return i-m+1+1;}}return -1;}int KMP(){getfail();return cmp();}void input(){scanf("%d%d",&n,&m);for (int i=0;i<n;i++){scanf("%d",&T[i]);};for (int i=0;i<m;i++){scanf("%d",&p[i]);}printf("%d\n",KMP());}int main(){int t;//freopen("1.txt","r",stdin);scanf("%d",&t);while(t--){input();}return 0;}
0 0
- hdu 1711 KMP模板题
- hdu 1711 kmp模板题
- KMP 模板 HDU 1711
- HDU 1711 KMP模板
- HDU-1711-kmp模板
- [KMP模板题]HDU-1711 Number Sequence
- hdu 1711 Number Sequence KMP模板题~~~
- HDU--1711(KMP模板题)
- hdu 1711 Number Sequence KMP模板题
- hdu 1711 KMP算法模板题
- hdu 1711 Number Sequence(kmp模板题)
- hdu 1711Number Sequence(kmp模板题)
- hdu 1711 Number Sequence KMP模板题
- Hdu 1711 Number Sequence (kmp模板题)
- HDU 1711 裸KMP,附KMP模板
- hdu 1358 & 1711 kmp 模板
- HDU 1711 KMP算法模板
- hdu 2203 kmp 模板题
- 内存数据网格hazelcast的一些机制原理
- POJ 1837-Balance(01背包)
- Algorithms—240.Search a 2D Matrix II
- 与时间相关的函数编程
- jsp页面中form表单提交到数据库的方法
- hdu 1711 KMP模板题
- Android ListView的setEmptyView方法的使用
- python StringIO和BytesIO
- python StringIO和BytesIO
- iOS开发系列--UITableView全面解析
- java poi导出execl类
- Android 适配横屏
- fzu1752 A^BmodC
- oracle exp EXP-00008: 遇到 ORACLE 错误 904