Oulipo----poj3461(kmp模板)
题目链接: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模板)的更多相关文章
- poj 3461 Oulipo(KMP模板题)
Oulipo Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 36903 Accepted: 14898 Descript ...
- POJ3461 KMP 模板题
最近忙着考研复习,所以刷题少了.. 数据结构昨天重新学习了一下KMP算法,今天自己试着写了写,问题还不少,不过KMP算法总归是理解了,以前看v_JULY_v的博客,一头雾水,现在终于懂了他为什么要在算 ...
- HDU 1686:Oulipo(KMP模板,子串出现次数)
Oulipo Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- POJ Oulipo KMP 模板题
http://poj.org/problem?id=3461 Oulipo Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4 ...
- Oulipo HDU 1686 KMP模板
题目大意:求模式串在主串中的出现次数. 题目思路:KMP模板题 #include<iostream> #include<algorithm> #include<cstri ...
- POJ Oulipo(KMP模板题)
题意:找出模板在文本串中出现的次数 思路:KMP模板题 #include<cstdio> #include<cstring> #include<cmath> #in ...
- HDU 1686 Oulipo(kmp)
Problem Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, w ...
- POJ 3461 Oulipo(——KMP算法)
Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, without t ...
- POJ 3461 Oulipo 【KMP统计子串数】
传送门:http://poj.org/problem?id=3461 Oulipo Time Limit: 1000MS Memory Limit: 65536K Total Submission ...
- POJ:3461-Oulipo(KMP模板题)
原题传送:http://poj.org/problem?id=3461 Oulipo Time Limit: 1000MS Memory Limit: 65536K Description The F ...
随机推荐
- CentOS6.5+nginx+mysql+php(laravel)服务器环境搭建
公司准备迭代会员中心项目,要上laravel框架,替代以前的Ecshop框架,PHP工程师将部分功能页面代码提交,自己也准备着手搭建一个测试环境将项目跑起来: 一. 环境依赖安装设置 关闭防火墙 [r ...
- swift侧开菜单
此文来自学习这篇博客后的学习笔记,原博客是用oc写的,我最近在学swift,于是改写为swift. swift和oc之间互相调用还是很方便的,但是要注意AnyObject和optional的运用,我现 ...
- spark源码 hashpartitioner
def nonNegativeMod(x: Int, mod: Int): Int = { val rawMod = x % mod rawMod + () mod ) def getPartitio ...
- [Linux内核]软中断、tasklet、工作队列
转自:http://www.cnblogs.com/li-hao/archive/2012/01/12/2321084.html 软中断.tasklet和工作队列并不是Linux内核中一直存在的机制, ...
- IOC控制反转
IOC是Inversion of Control的缩写,多数书籍翻译成“控制反转”,还有些书籍翻译成为“控制反向”或者“控制倒置”. 1996年,Michael Mattson在一篇有关探讨面 ...
- OS X删除自带的safari和facetime等程序
打开终端 cd /Applications/ //在应用程序文件目录删除苹果自带的程序 sudo rm -rf Safari.app/ //删除safari浏览器 sudo rm -rf Mail.a ...
- mysql -- 预处理语句
所谓预处理,即在真正执行某条SQL语句之前,先将SQL语句准备好,在执行过程中再绑定数据 语法: 准备预处理 prepare 预处理名字 from ‘要执行的SQL语句’ 执行预处理 execute ...
- Tomcat高并发配置优化
用的JMeter在自己电脑上测试的.Ubuntu10.04(x64)内存2G,cpu E5400 主频2.7.jdk1.6.0_27(x64) , tomcat6.0.33(x64) , oracle ...
- hdu 3599(最短路+最大流)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3599 思路:首先spfa求一下最短路,然后对于满足最短路上的边(dist[v]==dist[u]+w) ...
- VC启动一个新线程的三种方法
第一种AfxBeginThread() 用AfxBeginThread()函数来创建一个新线程来执行任务,工作者线程的AfxBeginThread的原型如下: CWinThread* AfxBegin ...