纯KMP,入门题,不知道读入挂加朴素匹配能不能过

 #include <cstdio>
#include <algorithm>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <stack>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cmath> using namespace std; int M,N,T;
int A[],B[];
int f[]; void getFail(int *P)
{
f[] = ;f[] = ;
for(int i=;i<M;i++)
{
int j = f[i];
while(j && P[i] != P[j]) j = f[j];
f[i+] = P[i] == P[j] ? j+ : ;
}
} int find(int *T,int *P)
{
getFail(P);
int j=;
for(int i=;i<N;i++)
{
while(j && T[i] != P[j]) j = f[j];
if( T[i] == P[j] ) j++;
if(j == M) return i-M+;
}
return -;
} int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&N,&M);
for(int i=;i<N;i++) scanf("%d",&A[i]);
for(int i=;i<M;i++) scanf("%d",&B[i]); printf("%d\n",find(A,B));
}
}

HDU1711-KMP-水题的更多相关文章

  1. poj-2406(kmp水题)

    题意:定义一个a*b=字符串a连接字符串b:给你一个字符串s,问你这个字符串最多能用多少个字符串t连接得到:例如:aaaa=4个a构成: 解题思路:kmp水题,next数组除了查找字串以外最广泛的一种 ...

  2. POJ 3641 Oulipo KMP 水题

    http://poj.org/problem?id=3461 直接KMP就好.水题 #include<cstdio> #include<cstring> const int M ...

  3. hdu 4763 Theme Section(KMP水题)

    Theme Section Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) To ...

  4. HDU1711(KMP入门题)

    Number Sequence Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  5. [hdu2594]kmp水题

    题意:求最长的a的前缀同时满足是b的后缀,把a,b连在一起,kmp跑一下,迭代next直到长度小于等于a,b长度的最小值为止,即为答案. #pragma comment(linker, "/ ...

  6. [hdu2087]kmp水题

    题意:求模板串在文本串中出现的次数(位置无交叉).只需在找到的时候把模板串指针归0即可. #pragma comment(linker, "/STACK:10240000,10240000& ...

  7. HDU - 2203 KMP水题

    循环移位的套路操作就是一份折开变两份 /*H E A D*/ void match(){ int n=strlen(T+1); int m=strlen(P+1); int j=0; rep(i,1, ...

  8. D - 楼下水题(kmp+Manacher)

    D - 楼下水题 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Statu ...

  9. POJ 水题(刷题)进阶

    转载请注明出处:優YoU http://blog.csdn.net/lyy289065406/article/details/6642573 部分解题报告添加新内容,除了原有的"大致题意&q ...

  10. ZOJ 17届校赛 Knuth-Morris-Pratt Algorithm( 水题)

    In computer science, the Knuth-Morris-Pratt string searching algorithm (or KMP algorithm) searches f ...

随机推荐

  1. 大牛blog

    分布式: 分布式基础学习[一] —— 分布式文件系统 分布式基础学习[二] —— 分布式计算系统(Map/Reduce) Java分布式应用技术架构介绍

  2. NPOI DataTable导出excel

    /// <summary> /// DataTable导出到Excel文件 /// </summary> /// <param name="dtSource&q ...

  3. virtual box问题记录

    1.已存在的虚拟机打开错误,可能是版本不一样的问题,我5.2.16版本,原虚拟机所属版本为4.3.12,换回4.3.12版本virtual box即可.

  4. openhtmltopdf 支持自定义字体、粗体

    一.支持自定义字体 private static void renderPDF(String html, OutputStream outputStream) throws Exception { t ...

  5. ASP.NETZERO 开发者指南-目录篇

    前面的话 此教程适用于 ASP.NET MVC 5.x & Angularjs 1.x  的ABP框架(收费需要授权) 所以有能力的朋友还是希望你们多多支持 土牛.购买链接:https://w ...

  6. 系统、决策、控制研究系列(SSDC)

    本类目主要介绍的书籍来自springer的系列书籍中的一本,对于该系列书籍介绍如下: “系统.决策及控制研究”(SSDC)系列涵盖了在广泛认知的系统.决策及控制的各个领域的快速.最新和高质量的最新发展 ...

  7. Python - 列表解析式

    列表解析——用来动态地创建列表 [expr for iter_var in iterable if cond_expr] 例子一: map(lambda x: x**2, range(6)) [0, ...

  8. Docker容器学习梳理 - 日常操作总结

    使用Docker已有一段时间了,今天正好有空梳理下自己平时操作Docker时的一些命令和注意细节: Docker 命令帮助 $ sudo docker Commands: attach Attach ...

  9. week3-构造一个简单的linux系统

    潘恒  原创作品转载请注明出处  <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 一.gdb跟踪调试内核 ...

  10. linux内实践核分析模块