【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& ...
随机推荐
- Java 将html导出word格式
@RequestMapping("download") public void exportWord( HttpServletRequest request, HttpServle ...
- Android日历开发之右上角标注红点事件
1.效果如下所示: 2.方法: 前提:已经知道如何在右上角画圆点的情况下. 这是一个任务显示器,每个任务都有一个时间,比如2014.01.12. 如果要标注2016.08 ...
- [Deep dig] ViewController初始化过程调查
代码:https://github.com/xufeng79x/ViewControllerLife 1.简介: 介绍xib方式.storyborad方式以及code方式下ViewController ...
- Java-贪心算法
1. 什么是贪心算法? 贪心算法,又称贪婪算法(Greedy Algorithm),是指在对问题求解时,总是做出在当前看来是最好的选择.也就是说,不从整体最优解出发来考虑,它所做出的仅是在某种意义上的 ...
- Python在线教程
Python 3.x的 http://www.ziqiangxuetang.com/python3/python3-stdlib.html 廖雪峰的官方网站 http://www.liaoxuefen ...
- hihocoder 1178 : 计数
#1178 : 计数 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Rowdark是一个邪恶的魔法师.在他阅读大巫术师Lich的传记时,他发现一类黑魔法来召唤远古生物, ...
- BNU - 49102
进化之地(Evoland) Time Limit: 1000ms Case Time Limit: 1000ms Memory Limit: 65536KB 64-bit integer IO for ...
- poj 1182 (扩展并查集)
食物链 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 58979 Accepted: 17247 Description ...
- AIOps实践三板斧:从可视化、自动化到智能化
http://ai.51cto.com/art/201806/576881.htm?mobile
- 微软企业库5.0 学习之路——第七步、Cryptographer加密模块简单分析、自定义加密接口及使用—下篇
在上一篇文章中, 我介绍了企业库Cryptographer模块的一些重要类,同时介绍了企业库Cryptographer模块为我们提供的扩展接口,今天我就要根据这些 接口来进行扩展开发,实现2个加密解密 ...