tjut 5918
来源:互联网 发布:gta5捏脸数据女爱丽丝 编辑:程序博客网 时间:2024/05/22 17:21
#include <iostream>#include <cstring>#include <stdio.h>#include <stdlib.h>#include <algorithm>using namespace std;const int N = 1000002;int Next[N];int A[N],S[N], T[N];int slen, tlen;void getNext(){ int j, k; j = 0; k = -1; Next[0] = -1; while(j < tlen) if(k == -1 || T[j] == T[k]) Next[++j] = ++k; else k = Next[k];}/*返回模式串在主串S中出现的次数*/int KMP_Count(){ int ans = 0; int i, j = 0; if(slen == 1 && tlen == 1) { if(S[0] == T[0]) return 1; else return 0; } for(i = 0; i < slen; i++) { while(j > 0 && S[i] != T[j]) j = Next[j]; if(S[i] == T[j]) j++; if(j == tlen) { ans++; j = Next[j]; } } return ans;}int main(){ int tcase,t=1; scanf("%d",&tcase); while(tcase--) { int n,k; scanf("%d%d%d",&n,&tlen,&k); memset(T,0,sizeof(T)); for(int i=0;i<n;i++) scanf("%d",&A[i]); for(int i=0;i<tlen;i++) scanf("%d",&T[i]); int ans = 0; getNext(); for(int i=0;i<k;i++){ ///枚举起点 slen = 0; for(int j = i;i+(tlen-1)*k<n&&j<n;j+=k){ S[slen++] = A[j]; } if(slen<tlen) continue; /*for(int j=0;j<slen;j++){ printf("%d ",S[j]); }*/ ans+=KMP_Count(); } printf("Case #%d: %d\n",t++,ans); } return 0;}
0 0
- tjut 5918
- tjut 5289
- tjut 5288
- tjut 5294
- tjut 2586
- tjut 5296
- tjut 5297
- tjut 5299
- tjut 5384
- tjut 5387
- tjut 5386
- tjut 5381
- tjut 5400
- tjut 5399
- tjut 5396
- tjut 5398
- tjut 5412
- tjut 5410
- 【JZOJ4824】配对游戏
- 抽象类
- poj 1743 后缀数组+二分答案 求一个串的最长无重叠的重复出现次数最多的子串
- Tomcat介绍
- rand()&srand()
- tjut 5918
- Python中的变量
- cordova 插件的使用说明
- 【JZOJ4859】【NOIP2016提高A组集训第7场11.4】连锁店
- 堆排列
- 《OpenCV3.0 编程入门》书中3.1.9节图像的载入、显示与输出示例程序练习报异常问题
- 重建二叉树106. Construct Binary Tree from Inorder and Postorder Traversal
- 编写程序STUDENT *Create(STUDENT studs[],int n)。STUDENT是一个结构类型,包含姓名、成绩和指针域。studs数组中存储了n个STUDENT记录。create函
- 网易视频云郭再荣:打造一体化多场景的视频云平台