Oulipo HDU 1686 KMP模板
题目大意:求模式串在主串中的出现次数.
题目思路:KMP模板题
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<stdio.h>
#include<stdlib.h>
#include<queue>
#include<math.h>
#include<map>
#define INF 0x3f3f3f3f
#define MAX 1000005
#define Temp 1000000000
#define MOD 1000000007 using namespace std; char str1[MAX],str2[MAX];
int n,m,Next[MAX]; void getNext()
{
int k=-,i=;
Next[]=-;
while(i<m)
{
if(k==- || str1[i]==str2[k])
Next[++i]=++k;
else
k=Next[k];
}
} int Kmp_const()
{
getNext();
int i=,j=,ans=;
while(i<n && j<m)
{
if(j==- || str1[i]==str2[j])
{
i++;
j++;
}
else
j=Next[j];
if(j==m)
{
ans++;
j=Next[j];
}
}
return ans;
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%s",str2);
scanf("%s",str1);
n=strlen(str1);
m=strlen(str2);
int ans=Kmp_const();
printf("%d\n",ans);
}
return ;
}
Oulipo HDU 1686 KMP模板的更多相关文章
- hdu 1686 KMP模板
// hdu 1686 KMP模板 // 没啥好说的,KMP裸题,这里是MP模板 #include <cstdio> #include <iostream> #include ...
- Oulipo - HDU 1686 (KMP模板题)
题目大意:题目叙述很多,其实只看输入输出也能明白什么意思,给两个串W,T, 判断T串中包含几个串W. 分析:还是基础的KMP应用....................... 直接上代码. === ...
- HDU 1686 (KMP模式串出现的次数) Oulipo
题意: 求模式串W在母串T中出现的次数,各个匹配串中允许有重叠的部分. 分析: 一开始想不清楚当一次匹配完成时该怎么办,我还SB地让i回溯到某个位置上去. 后来仔细想想,完全不用,直接让模式串向前滑动 ...
- HDU 1686 & KMP
题意: 求模板在匹配串所有子串中出现次数. SOL: 本题与普通kmp有一点不同,因为待匹配串中的模板串可能相互包含. 我们考虑正常的kmp是在怎么做的 i = 1 2 3 4 5 6 7 8 9 … ...
- HDU 2087 kmp模板题
s为主串 t为模板串 求t的nextt 加const #include<stdio.h> #include<string.h> #include<algorithm> ...
- Oulipo HDU - 1686
The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e ...
- Number Sequence HDU 1711 KMP 模板
题目大意:两个数组匹配,求子串首次出现的位置. 题目思路:数组长度,比较大,朴素算法的时间复杂度为 m*n超时.KMP的时间复杂度为m+n可行. #include<iostream> #i ...
- hdu 1686 KMP算法
题意: 求子串w在T中出现的次数. kmp算法详解:http://www.cnblogs.com/XDJjy/p/3871045.html #include <iostream> #inc ...
- HDU 1686 Oulipo / POJ 3461 Oulipo / SCU 2652 Oulipo (字符串匹配,KMP)
HDU 1686 Oulipo / POJ 3461 Oulipo / SCU 2652 Oulipo (字符串匹配,KMP) Description The French author George ...
随机推荐
- oracle动态视图v$,v_$,gv$,gv_$与x$之间的关系
前言:在oracle运维的过程中,经常会使用到一些以V$开头的动态视图,比如V$session, 有一次偶然看到有人用V_$session, 初以为别人写错了,没想到desc v_$session以后 ...
- 设计模式 单例模式(Singleton) [ 转载2 ]
设计模式 单例模式(Singleton) [ 转载2 ] @author java_my_life 单例模式的结构 单例模式的特点: 单例类只能有一个实例. 单例类必须自己创建自己的唯一实例. 单例类 ...
- Dubbo协议与连接控制
协议参考手册 (+) (#) 推荐使用Dubbo协议 性能测试报告各协议的性能情况,请参见:性能测试报告 (+) dubbo:// (+) (#) Dubbo缺省协议采用单一长连接和NIO异步通讯,适 ...
- LeetCode OJ 42. Trapping Rain Water
Given n non-negative integers representing an elevation map where the width of each bar is 1, comput ...
- VS2010编译错误 LNK 2019 unresolved external symbol错误解决办法
Link错误有很多种,主要是没有在连接中加入lib文件路径,或者lib配置正确,传参错误 一个solution里面多个project之间引用其他project函数会出现这个错误,由于包含了头文件而没处 ...
- EXEC 和 SP_EXECUTESQL的区别
摘要: MSSQL为我们提供了两种动态执行sql语句的命令:EXEC 和 SP_EXECUTESQL.通常SP_EXECUTESQL更具优势,因为它提供了输入输出的接口,且能够重用执行计划,大大提高执 ...
- js中的随机数
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 38.利用接口做参数,写个计算器,能完成+-*/运算 (1)定义一个接口Compute含有一个方法int computer(int n,int m); (2)设计四个类分别实现此接口,完成+-*/运算 (3)设计一个类UseCompute,含有方法: public void useCom(Compute com, int one, int two) 此方法要求能够:1.用传递过来的对象调用comp
//接口Compute package jieKou; public interface Compute { int Computer(int n,int m); } //加 package jieK ...
- UIScrollView 加载多个view view还可以交换顺序(1)
#import "ViewController.h" #define kWidthOfScreen self.view.frame.size.width #define kHeig ...
- manifest中的largeHeap是干什么用的?
转 http://blog.csdn.net/jiaoyang623/article/details/8773445 今天群里有人讨论怎么给app分配超过100M的内存,有人亮出了largeHeap参 ...