题目链接:http://poj.org/problem?id=3461

减花布条 的题对比一下;

求s2中s1的个数kmp模板;

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std; const int N = 1e6+; char s1[N], s2[N];
int n, m, ans;
int Next[N]; void GetNext()
{
int i = , j = -;
Next[i] = j;
while(i<n)
{
if(j==- || s2[i] == s2[j])
Next[++i] = ++j;
else
j = Next[j];
}
}
void kmp()
{
int i = , j = ;
while(i<m)
{
if(j==- || s1[i] == s2[j])
i++,j++;
else
j = Next[j];
if(j == n)
{
ans++;
j=Next[j];
}
}
} int main()
{
int T;
scanf("%d", &T);
while(T--)
{
scanf("%s%s", s2, s1);
m = strlen(s1);
n = strlen(s2);
GetNext();
ans = ;
kmp();
printf("%d\n", ans);
}
return ;
}

Oulipo----poj3461(kmp模板)的更多相关文章

  1. poj 3461 Oulipo(KMP模板题)

    Oulipo Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 36903   Accepted: 14898 Descript ...

  2. POJ3461 KMP 模板题

    最近忙着考研复习,所以刷题少了.. 数据结构昨天重新学习了一下KMP算法,今天自己试着写了写,问题还不少,不过KMP算法总归是理解了,以前看v_JULY_v的博客,一头雾水,现在终于懂了他为什么要在算 ...

  3. HDU 1686:Oulipo(KMP模板,子串出现次数)

    Oulipo Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  4. POJ Oulipo KMP 模板题

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

  5. Oulipo HDU 1686 KMP模板

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

  6. POJ Oulipo(KMP模板题)

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

  7. HDU 1686 Oulipo(kmp)

    Problem Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, w ...

  8. POJ 3461 Oulipo(——KMP算法)

    Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, without t ...

  9. POJ 3461 Oulipo 【KMP统计子串数】

    传送门:http://poj.org/problem?id=3461 Oulipo Time Limit: 1000MS   Memory Limit: 65536K Total Submission ...

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

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

随机推荐

  1. ldap temp

    #http://www.openldap.org/software/man.cgi?query=slapcat&apropos=0&sektion=0&manpath=Open ...

  2. Groovy学习()面向Java开发者的Groovy

    第一段Groovy代码 // first groovy program for(int i = 0; i < 3; i++) { System.out.println("ho &quo ...

  3. 设计模式 ( 十二 ) 职责链模式(Chain of Responsibility)(对象行为)

     设计模式(十二)职责链模式(Chain of Responsibility)(对象行为型) 1.概述 你去政府部门求人办事过吗?有时候你会遇到过官员踢球推责,你的问题在我这里能解决就解决.不能解决就 ...

  4. 专题实验 Toad 用户的创建与管理( 包括 role 等 )

    1. 用户登录数据库 是否可以通过操作系统权限来登录数据库, $ORACLE_HOME/network/admin/sqlnet.ora 这个文件中设置, 如果增加参数sqlnet.authentic ...

  5. ASP.NET MVC4 异常拦截

    ASP.NET MVC4 程序发生异常时,通过拦截Action的异常,重写ActionFilterAttribute 的方法OnActionExecuted实现. 具体实现代码如下: /// < ...

  6. Android学习笔记36:使用SQLite方式存储数据

    在Android中一共提供了5种数据存储方式,分别为: (1)Files:通过FileInputStream和FileOutputStream对文件进行操作.具体使用方法可以参阅博文<Andro ...

  7. Application应用程序级变量

    对于每一个网站访问用户都要访问的变量,应该将它设为________变量.(选择1项) A. Session B. Reques C. Response D. Application 解答:D

  8. jquery -- 触屏设备touch事件

    几种普及得比较好的触摸事件,你可以在绝大多数现代浏览器中来测试这一事件(必须是触屏设备哦): touchstart:触摸开始的时候触发 touchmove:手指在屏幕上滑动的时候触发 touchend ...

  9. 让div也出现滑动框。

    <div id="box" style="height: 300px; width: 200px; border:1px solid #CCC; overflow: ...

  10. oracle和SQLserver数据库中select into 的区别

    在Oracle中是这样的 在SQLserver中是这样的