HDU1711-KMP-水题
纯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-水题的更多相关文章
- poj-2406(kmp水题)
题意:定义一个a*b=字符串a连接字符串b:给你一个字符串s,问你这个字符串最多能用多少个字符串t连接得到:例如:aaaa=4个a构成: 解题思路:kmp水题,next数组除了查找字串以外最广泛的一种 ...
- POJ 3641 Oulipo KMP 水题
http://poj.org/problem?id=3461 直接KMP就好.水题 #include<cstdio> #include<cstring> const int M ...
- hdu 4763 Theme Section(KMP水题)
Theme Section Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
- HDU1711(KMP入门题)
Number Sequence Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- [hdu2594]kmp水题
题意:求最长的a的前缀同时满足是b的后缀,把a,b连在一起,kmp跑一下,迭代next直到长度小于等于a,b长度的最小值为止,即为答案. #pragma comment(linker, "/ ...
- [hdu2087]kmp水题
题意:求模板串在文本串中出现的次数(位置无交叉).只需在找到的时候把模板串指针归0即可. #pragma comment(linker, "/STACK:10240000,10240000& ...
- 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, ...
- D - 楼下水题(kmp+Manacher)
D - 楼下水题 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Submit Statu ...
- POJ 水题(刷题)进阶
转载请注明出处:優YoU http://blog.csdn.net/lyy289065406/article/details/6642573 部分解题报告添加新内容,除了原有的"大致题意&q ...
- ZOJ 17届校赛 Knuth-Morris-Pratt Algorithm( 水题)
In computer science, the Knuth-Morris-Pratt string searching algorithm (or KMP algorithm) searches f ...
随机推荐
- LVDS时序分析
LVDS时序分析 2012年05月07日 11:48:08 Walle 阅读数:3355 标签: 平台工作 最近在调试基于telechip平台的LVDS驱动,一开始对该平台的LVDS时序不是很了解 ...
- (一)在 Blend 中绘制形状和路径
原文:(一)在 Blend 中绘制形状和路径 https://docs.microsoft.com/zh-cn/previous-versions/jj170881(v=vs.120) 在 Blend ...
- Ionic2 播放mp3功能实现
在开发app的过程中有需要播放mp3的功能,一直想实现,但苦于具体的困难一直未能实现,经过一段时间的资料查询和测试,最终摸索出来,现记录如下: 1.最重要的是安装第三方插件ionic-audio,开源 ...
- Oracle 社区动态、中文讲座,最佳实践
https://community.oracle.com/thread/3789691https://community.oracle.com/community/support/%E4%B8%AD% ...
- 运行supervisorctl reload报错解决方法
在进行守护进程时运行supervisorctl reload出现“error: <class 'socket.error'>, [Errno 2] No such file or dire ...
- 记一次拿webshell踩过的坑(如何用PHP编写一个不包含数字和字母的后门)
0x01 前言 最近在做代码审计的工作中遇到了一个难题,题目描述如下: <?php include 'flag.php'; if(isset($_GET['code'])){ $code = $ ...
- Microsoft Office软件自定义安装目录
Microsoft Office安装时不能手动设置安装目录,本文描述通过修改注册表的方式自定义安装目录 1.同时按下快捷键 win + r 启动运行 2.输入 regedit 打开注册表 3.找到 ...
- [LeetCode] 307. Range Sum Query - Mutable 解题思路
Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive ...
- this.$http.post ||this.$http.put||vue 获取url参
getClasslist() { this.$http.get('/xxxxx/childlist', { params: { ServiceUnitId: localStorage.getItem( ...
- 五子棋游戏SRS文档
SRS技术文档,包括对SRS的解释说明.SRS描述规范.软件需求规格说明书(SRS,Software Requirement Specification)是为了软件开发系统而编写的,主要用来描 ...