题目大意:题目叙述很多,其实只看输入输出也能明白什么意思,给两个串W,T, 判断T串中包含几个串W。
 
分析:还是基础的KMP应用.......................
直接上代码。
==================================================================================================================
#include<stdio.h>
#include<string.h> const int MAXM = 1e4+;
const int MAXN = 1e6+; void GetNext(char s[], int next[], int N)
{
int i=, j=-;
next[] = -; while(i < N)
{
if(j==- || s[i]==s[j])
next[++i] = ++j;
else
j = next[j];
}
}
int KMP(char W[], char T[], int Nw, int Nt)
{
static int next_w[MAXM];
int i=, j=, ans=; GetNext(W, next_w, Nw); while(i < Nt)
{
while(j==- || (T[i] == W[j] && i<Nt) )
i++, j++; if(j == Nw)
ans++;
j = next_w[j];
} return ans;
} int main()
{
int ncase; scanf("%d", &ncase); while(ncase--)
{
static char W[MAXM], T[MAXN];
int Nw, Nt; scanf("%s%s", W, T); Nw = strlen(W);
Nt = strlen(T); int ans = KMP(W, T, Nw, Nt); printf("%d\n", ans);
} return ;
}

Oulipo - HDU 1686 (KMP模板题)的更多相关文章

  1. Oulipo HDU 1686 KMP模板

    题目大意:求模式串在主串中的出现次数. 题目思路:KMP模板题 #include<iostream> #include<algorithm> #include<cstri ...

  2. hdu 1686 KMP模板

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

  3. HDU 2087 kmp模板题

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

  4. HDU 1711 - Number Sequence - [KMP模板题]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1711 Time Limit: 10000/5000 MS (Java/Others) Memory L ...

  5. POJ Oulipo KMP 模板题

    http://poj.org/problem?id=3461 Oulipo Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4 ...

  6. POJ Oulipo(KMP模板题)

    题意:找出模板在文本串中出现的次数 思路:KMP模板题 #include<cstdio> #include<cstring> #include<cmath> #in ...

  7. Number Sequence - HDU 1711(KMP模板题)

    题意:给你一个a串和一个b串,问b串是否是a串的子串,如果是返回b在a中最早出现的位置,否则输出-1   分析:应该是最简单的模板题了吧..... 代码如下: ==================== ...

  8. hdu 1711 Number Sequence(KMP模板题)

    我的第一道KMP. 把两个数列分别当成KMP算法中的模式串和目标串,这道题就变成了一个KMP算法模板题. #include<stdio.h> #include<string.h> ...

  9. HDU 1711Number Sequence【KMP模板题】

    <题目链接> 题目大意: 意思是给出两个串,找出匹配串在模式串中的位置. 解题分析: KMP算法模板题. #include <cstdio> #include <cstr ...

  10. POJ:3461-Oulipo(KMP模板题)

    原题传送:http://poj.org/problem?id=3461 Oulipo Time Limit: 1000MS Memory Limit: 65536K Description The F ...

随机推荐

  1. mysql 远程访问 配置

    sudo vi /etc/mysql/my.cnf 找到bind-address = 127.0.0.1 注释掉这行:#bind-address = 127.0.0.1 或者改为: bind-addr ...

  2. SQL SERVER 存储过程基础

    一.注释 -- 单行注释,从这到本行结束为注释,类似C++,c#中// /* … */ 多行注释,类似C++,C#中/* … */ 二.变量 (int, smallint, tinyint, deci ...

  3. ASIHttpRequest网络请求第三方类库使用方法详解

    一. 第一步首先你要从网络上下载ASIHttpRequestlib, 下载以后解压,增加到你的工程里面, 这个时间检查工程内部是否已经导入成功,文件结构如下: ASIHTTPRequestConfig ...

  4. Linux命令:scp命令(文件上传和下载)

    #本地下载远端文件 并且重命名(从本地机器下载远端) scp webmaster@10.10.65.103:/ROOT/logs/tomcate.log /home/dajie/mywork/newn ...

  5. SOAPUI请求及mockservice 使用

    1.新建soap Project,输入wsdl的地址,运行request                                                               2 ...

  6. 用arm-linux-gcc v4.3.4交叉编译Qt4.8.3

    1.解压缩 #tar zxvf  qt-everywhere-opensource-src-4.8.3.tar.gz 2. configure #mkdir buildarm-static #cd b ...

  7. JS获取浏览器可视区域的尺寸

    所谓可视区域是指能看得见的区域,即在浏览器中能看到页面的区域(高度与宽度).刚刚使用 document.body.clientHeight 来获取可视区域的高度得到的却是整个文档的高度,然后在cnbl ...

  8. thinkphp 中js 实现刷新

    <input name="Button5" value="返回" id="Button5" style="width:56p ...

  9. js touch触屏原理分析

    之前我们做过许多触屏的特效,那么,今天,我们来分析下js的触屏原理.事实上,大家百度一下js touch基本上可以找到这文章“指尖下的js ——多触式web前端开发之一:对于Touch的处理”,我想这 ...

  10. IOS开发备忘

    1. ios 真机调试时出现CopyPngFile error解决方法 说是读取的时候没有找到这张图片,检查了一下图片路径,没有问题,于是google之,找到两种解决方法 : 方法一:在build s ...