hdu1686 Oulipo kmp
思路:kmp模板,稍微修改下
#include<bits/stdc++.h>
#define clr(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const int maxn=;
char p[maxn],t[maxn];
int f[maxn],n,m,ans;
void fail(){
f[]=-;
for(int j=;j<m;j++)
{
for(int i=f[j-];;i=f[i]){
if(p[j]==p[i+]){
f[j]=i+;
break;
}else if(i==-){
f[j]=-;
break;
}
}
}
}
int kmp(){
fail();
int i=,j=;
while(i<n&&j<m)
{
if(t[i]==p[j]){
i++,j++;
if(j==m){
ans++;
j=f[j-]+;//如果匹配完了,在接下来的位置还能匹配的话,那么还是回到前缀
}
}else if(j==){
i++;
}else{
j=f[j-]+;
}
}
return ans;
}
int main(){
int T;
cin>>T;
while(T--)
{
scanf("%s",p);
scanf("%s",t);
m=strlen(p),n=strlen(t);
ans=;
printf("%d\n",kmp());
}
}
hdu1686 Oulipo kmp的更多相关文章
- hdu1686 Oulipo KMP/AC自动机
The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e ...
- 洛谷 P3375 【模板】KMP字符串匹配 || HDU 1686 Oulipo || kmp
HDU-1686 P3375 kmp介绍: http://www.matrix67.com/blog/archives/115 http://www.cnblogs.com/SYCstudio/p/7 ...
- kuangbin专题十六 KMP&&扩展KMP HDU1686 Oulipo
The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e ...
- [hdu1686] Oulipo【KMP】
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1686 保存KMP模版,代码里P是模版串,next[]就是为它建立的.T是文本串,就是一般比较长的.nex ...
- HDU1686 Oulipo 题解 KMP算法
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1686 题目大意:给你一个子串t和一个母串s,求s中有多少个子串t. 题目分析:KMP模板题. cal_ ...
- poj3461 Oulipo(KMP模板)
Oulipo Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 17795 Accepted: 7160 Descripti ...
- Oulipo (kmp)
Oulipo Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 26857 Accepted: 10709 Descript ...
- hdu 1686 Oulipo KMP匹配次数统计
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1686 分析:典型的KMP算法,统计字符串匹配的次数. 用Next数组压缩时间复杂度,要做一些修改. / ...
- HDU-1686 Oulipo
学习:重点理解这句话的意思: next[j]会告诉我们从哪里开始匹配 模板题. Oulipo Time Limit: 3000/1000 MS (Java/Others) Memory ...
随机推荐
- #Pragma Pack与内存分配
博客转载自:https://blog.csdn.net/mylinx/article/details/7007309 #pragma pack(n) 解释一: 每个特定平台上的编译器都有自己的默认“对 ...
- wamp安装两个,数据库丢了,怎么办
wampserver3.*下载了好几天一直没有安装,今天发现必须安装,已升级自己的php版本,不过也饿可以自己手动配置PHP版本,既然有安装包就算了吧,当安装完后,发现忘记备份自己的数据库了,幸好之前 ...
- WCF项目问题2-无法激活服务,因为它需要 ASP.NET 兼容性。没有未此应用程序启用 ASP.NET 兼容性。请在 web.config 中启用 ASP.NET 兼容性,或将 AspNetCompatibilityRequirementsAttribute.AspNetCompatibilityRequirementsMode 属性设置为 Required 以外的值。
无法激活服务,因为它需要 ASP.NET 兼容性.没有未此应用程序启用 ASP.NET 兼容性.请在 web.config 中启用 ASP.NET 兼容性,或将 AspNetCompatibility ...
- 引用母版页的内容页添加CSS文件
在内容页当中定义一个类然后调用内中的方法即可 public static class addstyle{ //可以不用实例化 public static void addstylesheet(Pag ...
- Canvas保存为图片
public static void GenerateCanvas(string imgSaveName, int canvasWidth, int canvasHeight, string imgD ...
- Node简单服务器开发
运用的知识:http,fs,get,post 接口定义:/user?act=reg$user=aaa&pass=bbb后台返回格式:{"ok":false,"ms ...
- Stars in Your Window(线段树求最大矩形交)
题目连接 http://poj.org/problem?id=2482 Description Fleeting time does not blur my memory of you. Can it ...
- NSArray 数组
前言 数组只能存储 OC 对象,不能存储 C 语言中的基本数据类型,也不能存储 nil . Xcode 7 对系统中常用的一系列容器类型都增加了泛型支持(),有了泛型后就可以指定容器类中对象的类型了. ...
- 渗透测试工具实战技巧 (转载freebuf)
最好的 NMAP 扫描策略 # 适用所有大小网络最好的 nmap 扫描策略 # 主机发现,生成存活主机列表 $ nmap -sn -T4 -oG Discovery.gnmap 192.168.56. ...
- mysql主从复制数据库
mysql主从复制相信已经用得很多了,但是由于工作原因一直没怎么用过.趁着这段时间相对空闲,也就自己实现一遍.尽管互联网上已有大把类似的文章,但是自身实现的仍然值得记录. 环境: 主服务器:cento ...