【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& ...
随机推荐
- 双关键字LIS
首先对于双关键字的LIS有一个比较暴力的方法,就是线段树套平衡树,我们把双关键字的LIS抽象成二维坐标系中的点,这样我们对于当前转移的点i(x,y),需要找的就是在(xx,yy)xx<x,yy& ...
- hdu 1241Oil Deposits(BFS)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1241 Oil Deposits Time Limit: 2000/1000 MS (Java/Othe ...
- mave的依赖范围
compile(编译范围) compile是默认的范围:如果没有提供一个范围,那该依赖的范围就是编译范 围.编译范围依赖在所有的classpath中可用,同时它们也会被打包. provided(已提供 ...
- perl6 拖库脚本
#注入点: #https://fei.sg/shop/products.php?action=content&id=-23 #check mysql column_name of the sq ...
- Python脚本 - 常用单位转换
测试系统为:Centos 6.7 Python版本为: 3.6.4 脚本功能:常用单位的转换,这里用内存来模拟 import pstuil def bytes2human(n): symbols = ...
- [Leetcode Week17]Copy List with Random Pointer
Copy List with Random Pointer 题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/copy-list-with-random- ...
- 006 Java并发编程wait、notify、notifyAll和Condition
原文https://www.cnblogs.com/dolphin0520/p/3920385.html#4182690 Java并发编程:线程间协作的两种方式:wait.notify.notifyA ...
- IoT之车联网
一. 背景 这是一个笔者在实习公司策划的关于车联网的小项目,也是笔者参加某竞赛的作品<基于云平台的车内滞留儿童状况监测与处理>,本项目旨在为因各种原因导致儿童滞留车内热死.闷死的社会性事件 ...
- dos命令连接mysql并且查看编码方式
打开cmd: 输入:mysql -hlocalhost -uroot -p 然后: show variables like 'char%';
- 多路复用I/O模型poll() 模型 代码实现
多路复用I/O模型poll() 模型 代码实现 poll()机制和select()机制是相似的,都是对多个描述符进行轮询的方式. 不同的是poll()没有描述符数目的限制. 是通过struct pol ...