hdu1711 KMP
来源:互联网 发布:linux 加载u盘 编辑:程序博客网 时间:2024/05/20 18:17
#include <bits/stdc++.h> using namespace std; const int maxn=1e6+10; int str[maxn],mo[maxn],N,M; int Next[maxn]; void getnext() { int i=0,j=-1; while(i<M) { if(j==-1||mo[i]==mo[j]){Next[++i]=++j;} else j = Next[j]; } } int KMP() { int i=0,j=0; int ans=0; while(i<N) { if(j==-1||mo[j]==str[i])i++,j++; else j=Next[j]; if(j==M)return i-M+1; } return -1; } int main() { int t,i; scanf("%d",&t); while(t--) { scanf("%d %d",&N,&M); for(i=0;i<N;i++)scanf("%d",&str[i]); for(i=0;i<M;i++)scanf("%d",&mo[i]); if(M>N)printf("-1\n"); else{ Next[0]=-1; getnext(); printf("%d\n",KMP()); } } return 0; }
阅读全文
0 0
- kmp hdu1711
- hdu1711 kmp
- hdu1711(kmp)
- HDU1711-KMP
- hdu1711 KMP
- hdu1711 kmp
- HDU1711 KMP
- HDU1711 (KMP)
- hdu1711 KMP
- KMP-hdu1711
- hdu1711 KMP模板
- Number Sequence hdu1711 KMP
- hdu1711之入门KMP
- hdu1711 Number Sequence,KMP
- hdu1711 Number Sequence (KMP)
- HDU1711 模板题-KMP
- hdu1711 Number Sequence---KMP
- hdu1711 KMP模板
- SQL--锁
- Mybatis 之List<?>传参的注意事项和原理
- Source Insight4.0问题总结
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals)-831C Jury Marks(思维)
- C语言的奇技淫巧
- hdu1711 KMP
- 【PAT】【Advanced Level】1013. Battle Over Cities (25)
- 详解C中volatile关键字
- C++案例分析
- day05(数组)
- Android自定义万能Canvas画布
- Excel比较工具SpreadSheet
- Android开发中如何设置字体
- 【PAT】【Advanced Level】1014. Waiting in Line (30)