题目大意:求模式串在主串中的出现次数.

题目思路:KMP模板题

#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<stdio.h>
#include<stdlib.h>
#include<queue>
#include<math.h>
#include<map>
#define INF 0x3f3f3f3f
#define MAX 1000005
#define Temp 1000000000
#define MOD 1000000007 using namespace std; char str1[MAX],str2[MAX];
int n,m,Next[MAX]; void getNext()
{
int k=-,i=;
Next[]=-;
while(i<m)
{
if(k==- || str1[i]==str2[k])
Next[++i]=++k;
else
k=Next[k];
}
} int Kmp_const()
{
getNext();
int i=,j=,ans=;
while(i<n && j<m)
{
if(j==- || str1[i]==str2[j])
{
i++;
j++;
}
else
j=Next[j];
if(j==m)
{
ans++;
j=Next[j];
}
}
return ans;
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%s",str2);
scanf("%s",str1);
n=strlen(str1);
m=strlen(str2);
int ans=Kmp_const();
printf("%d\n",ans);
}
return ;
}

Oulipo HDU 1686 KMP模板的更多相关文章

  1. hdu 1686 KMP模板

    // hdu 1686 KMP模板 // 没啥好说的,KMP裸题,这里是MP模板 #include <cstdio> #include <iostream> #include ...

  2. Oulipo - HDU 1686 (KMP模板题)

    题目大意:题目叙述很多,其实只看输入输出也能明白什么意思,给两个串W,T, 判断T串中包含几个串W.   分析:还是基础的KMP应用....................... 直接上代码. === ...

  3. HDU 1686 (KMP模式串出现的次数) Oulipo

    题意: 求模式串W在母串T中出现的次数,各个匹配串中允许有重叠的部分. 分析: 一开始想不清楚当一次匹配完成时该怎么办,我还SB地让i回溯到某个位置上去. 后来仔细想想,完全不用,直接让模式串向前滑动 ...

  4. HDU 1686 & KMP

    题意: 求模板在匹配串所有子串中出现次数. SOL: 本题与普通kmp有一点不同,因为待匹配串中的模板串可能相互包含. 我们考虑正常的kmp是在怎么做的 i = 1 2 3 4 5 6 7 8 9 … ...

  5. HDU 2087 kmp模板题

    s为主串 t为模板串 求t的nextt 加const #include<stdio.h> #include<string.h> #include<algorithm> ...

  6. Oulipo HDU - 1686

    The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e ...

  7. Number Sequence HDU 1711 KMP 模板

    题目大意:两个数组匹配,求子串首次出现的位置. 题目思路:数组长度,比较大,朴素算法的时间复杂度为 m*n超时.KMP的时间复杂度为m+n可行. #include<iostream> #i ...

  8. hdu 1686 KMP算法

    题意: 求子串w在T中出现的次数. kmp算法详解:http://www.cnblogs.com/XDJjy/p/3871045.html #include <iostream> #inc ...

  9. HDU 1686 Oulipo / POJ 3461 Oulipo / SCU 2652 Oulipo (字符串匹配,KMP)

    HDU 1686 Oulipo / POJ 3461 Oulipo / SCU 2652 Oulipo (字符串匹配,KMP) Description The French author George ...

随机推荐

  1. LINUX nfs服务

    1.什么是NFS(Network FileSystem)  NFS 就是 Network FileSystem 的缩写,最早之前是由 Sun 所发展出来的.他最大的功能就是可以透过网络,让不同的机器. ...

  2. 判断浏览器是否支持html5和css3属性

    本文章内容是由一个前辈写的. CSS3特有的属性moz-Transform //判断是否具有相应属性 testProps: function (props) { var i; for (i in pr ...

  3. Nginx 搭建反向代理服务器过程详解

    1.1 反向代理初印象 反向代理(Reverse Proxy)方式是指以代理服务器来接受internet上的连接请求,然后将请求转发给内部网络上的服务器,并将从服务器上得到的结果返回给internet ...

  4. HDU 2461 Rectangles#容斥原理

    http://acm.hdu.edu.cn/showproblem.php?pid=2461 题目很简单,但是由于询问数M可以很大,所以容易超时,这道题学到了在结构体里面写函数的方法,这样子效率更高, ...

  5. hdu_3341_Lost's revenge(AC自动机+状态hashDP)

    题目链接:hdu_3341_Lost's revenge 题意: 有n个模式串,一个标准串,现在让标准串重组,使得包含最多的模式串,可重叠,问重组后最多包含多少模式串 题解: 显然是AC自动机上的状态 ...

  6. Git 忽略特殊文件的功能

    有些时候,你必须把某些文件放到Git工作目录中.但是又不能提交他们,比如保存了数据库密码的配置文件等,每次git status都会 显示“untracked files”,如果有强迫症的你心里肯定不舒 ...

  7. ural 1261. Tips(进制运算)

    1261. Tips Time limit: 1.0 secondMemory limit: 64 MB The favorite resting place of the Ural programm ...

  8. jspl零散知识点

    1.  读取配置文件. index.jsp: <body> <% String charset=config.getInitParameter("charset" ...

  9. caffe+NVIDIA安装+CUDA-7.5+ubuntu14.04(显卡GTX1080)

    首先强调,我们实验室的机器是3.3w的机器,老板专门买来给我们搞深度学习,其中显卡是NVIDIA GeForce  GTX1080(最近新出的,装了两块),cpu是intel i7处理器3.3Ghz, ...

  10. WebService测试方案

    1.WebService简介 WebService是一种革命性的分布式计算技术,本质上就是网络上可用的API,可以直接在网络环境调用的方法. WebService常用的框架有axis.xfire.cx ...