【KMP模板】POJ3461-Oulipo
【题意】
找出第一个字符串在第二个字符串中出现次数。
【注意点】
一定要先将strlen存下来,而不能每次用每次求,否则会TLE!
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int MAXN=+;
const int MAXM=+;
char t[MAXN],p[MAXN];
int next[MAXM];
int lent,lenp; void getnext()
{
int i=,j=-;
next[i]=j;
while (i<lenp)
{
if (j==- || p[i]==p[j]) next[++i]=++j;
else j=next[j];
}
} int getans()
{
int i=,j=,ans=;
while (i<lent)
{
if (t[i]==p[j] || j==-)
{
i++;
j++;
}
else j=next[j];
if (j==lenp)//如果匹配成功,则视作这次匹配失败,返回到上一次。
{
ans++;
j=next[j-];
i--;
}
}
return ans;
} int main()
{
int kase;
scanf("%d",&kase);
for (int i=;i<kase;i++)
{
scanf("%s%s",p,t);
lent=strlen(t);
lenp=strlen(p);//注意一定要先把strlen存下来,否则会TLE!
getnext();
cout<<getans()<<endl;
}
return ;
}
【KMP模板】POJ3461-Oulipo的更多相关文章
- 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 ...
- POJ:3461-Oulipo(KMP模板题)
原题传送:http://poj.org/problem?id=3461 Oulipo Time Limit: 1000MS Memory Limit: 65536K Description The F ...
- hdu 1686 KMP模板
// hdu 1686 KMP模板 // 没啥好说的,KMP裸题,这里是MP模板 #include <cstdio> #include <iostream> #include ...
- KMP模板(bin)
KMP模板 主要是kuangbin的模板,之后加了一点我的习惯和理解. kmpN() 作用:构造next数组 参数:模式串,模式串长度 kmpC() 作用:返回模式串在主串中出现的次数(可重复) 参数 ...
- HDU 1711 - Number Sequence - [KMP模板题]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1711 Time Limit: 10000/5000 MS (Java/Others) Memory L ...
- HDU 1711 Number Sequence(KMP模板)
http://acm.hdu.edu.cn/showproblem.php?pid=1711 这道题就是一个KMP模板. #include<iostream> #include<cs ...
- 剪花布条---hdu2087(kmp模板)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2087 kmp模板题: #include <cstdio> #include <cst ...
- Oulipo----poj3461(kmp模板)
题目链接:http://poj.org/problem?id=3461 和 减花布条 的题对比一下: 求s2中s1的个数kmp模板: #include<stdio.h> #include& ...
随机推荐
- js基础知识点收集
js基础知识点收集 js常用基本类型 function show(x) { console.log(typeof(x)); // undefined console.log(typeof(10)); ...
- sass_sass安装
你会不会因为有些事遇到各种各样的问题而搁置,直到把这个事情被耽误了几天.最近一直在弄sass这个东西,安装的过程中各种问题.sass是一个基于ruby环境开发的,安装sass之前得先把ruby给安装了 ...
- 2.0 docker安装
问题列表: Error: Cannot retrieve metalink for repository: epel. Please verify its path and try again 解:处 ...
- GBK UTF-16 UTF-8 编码表
GBK UTF-16 UTF-8 ================== D2BB 4E00 E4 B8 80 一 B6A1 4E01 E4 B8 81 丁 C6DF 4E03 E4 ...
- smb windows中使用的文件共享协议(主要用于与windows互通)
主要是samba服务. SMB协议又成为CIFS(Common Internet File System)协议 samba服务功能: 1文件共享 2打印共享 3加入windows2000/2003/2 ...
- HDU 5129 Yong Zheng's Death
题目链接:HDU-5129 题目大意为给一堆字符串,问由任意两个字符串的前缀子串(注意断句)能组成多少种不同的字符串. 思路是先用总方案数减去重复的方案数. 考虑对于一个字符串S,如图,假设S1,S2 ...
- git - 开发者电脑与服务器的配置
首先公司要有一台git服务器,现在一般都托管在github服务器上,在中国可能会托管到oschina上,oschina有一点好处就是可以免费托管私有项目,而在github上想要托管自己的项目是收费的, ...
- saltstack安装和配置
[root@web9 salt]# vi filetest.sls //ADD file_test: file.managed: - name: /tmp/lulu.com - source: sal ...
- django开发项目实例3--用session是实现简单的登陆、验证登陆和注销功能
如果你的网页不是纯阅读型的,那么你很有可能希望在用户打开某些界面的时候需要验证用户是否登陆的信息, 虽然django里面有自带的一些user的类,但我看不懂,并且自己实现也不是很难,下面和大家分享一下 ...
- 机器学习方法(五):逻辑回归Logistic Regression,Softmax Regression
欢迎转载,转载请注明:本文出自Bin的专栏blog.csdn.net/xbinworld. 技术交流QQ群:433250724,欢迎对算法.技术.应用感兴趣的同学加入. 前面介绍过线性回归的基本知识, ...