POJ 3461 裸的KMP
直接贴代码吧
#include<cstdio>
#include<cstring>
char P[],T[];
int f[];
int n,m;
void getfail()
{
f[] = ;
f[] =;
for(int i=; i<m; ++i)
{
int j=f[i];
while(j && P[i] != P[j]) j = f[j];
f[i+] = P[i]==P[j] ? j+:;
}
}
int KMP()
{
int cnt=;
getfail();
int j=;
for(int i=; i<n; ++i)
{
while(j && P[j] != T[i]) j=f[j];
if(P[j] == T[i]) ++j;
if(j == m)
{
j=f[m];
++cnt;
}
}
return cnt;
}
int main()
{
freopen("in.txt","r",stdin);
int t;
scanf("%d",&t);
while(t--)
{
scanf("%s%s",P,T);
n=strlen(T);
m = strlen(P);
getfail();
for(int i=; i<=m; ++i)
printf("%d\n",f[i]);
}
return ;
}
POJ 3461 裸的KMP的更多相关文章
- POJ 3461 Oulipo[附KMP算法详细流程讲解]
E - Oulipo Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit ...
- POJ 3461 Oulipo(KMP裸题)
Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, without t ...
- POJ 3461 Oulipo 【KMP统计子串数】
传送门:http://poj.org/problem?id=3461 Oulipo Time Limit: 1000MS Memory Limit: 65536K Total Submission ...
- poj 3461 Oulipo(KMP模板题)
Oulipo Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 36903 Accepted: 14898 Descript ...
- POJ 3461 Oulipo(——KMP算法)
Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, without t ...
- poj 3461 - Oulipo 经典kmp算法问题
2017-08-13 19:31:47 writer:pprp 对kmp算法有了大概的了解以后,虽然还不够深入,但是已经可以写出来代码,(可以说是背会了) 所以这道题就作为一个模板,为大家使用吧. 题 ...
- poj 3461 Oulipo(kmp统计子串出现次数)
题意:统计子串出现在主串中的次数 思路:典型kmp #include<iostream> #include<stdio.h> #include<string.h> ...
- poj 3461 Oulipo(KMP)
Oulipo Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 49378 Accepted: 19617 Descript ...
- poj 3461 Oulipo,裸kmp
传送门 Oulipo Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 32373 Accepted: 13093 Desc ...
随机推荐
- URAL 1519 基础插头DP
题目大意: 给定一个图,一部分点'*'作为障碍物,求经过所有非障碍点的汉密尔顿回路有多少条 基础的插头DP题目,对于陈丹琦的论文来说我觉得http://blog.sina.com.cn/s/blog_ ...
- 【转】linux下如何查看某个软件 是否安装?安装路径在哪
以redhat\centos 中php-mysql为例1:如果包是通过yum或者rpm方式安装[root@localhost yum.repos.d]# rpm -qa //找出系统所有的包,找到对应 ...
- Visual Studio Ultimate 2013 with Update 4
Visual Studio Ultimate 2013 with Update 4 是一个先进的开发解决方案,各种规模的团队通过它均可设计和创建引人注目的应用程序,使用户兴致勃勃. Visual St ...
- Google https服务被屏蔽
根据Google透明度报告显示,从上周(5月27日)开始,Google的部分服务开始被屏蔽,其中最主要的是HTTPS搜索服务和Google登录服务,所有版本的Google都受到影响,包括Google. ...
- 升级到EntityFramework 6的注意事项
参考: http://social.msdn.microsoft.com/Forums/vstudio/en-US/aa542153-b2a5-4b14-98a3-572f7b028c61/updat ...
- NSURLSession使用实战教程
我的前面两篇文章介绍了NSURLSession套件的使用和NSURLSession套件的主要类.今天我们使用NSURLSession来完成一个小的应用程序.在实战之前,我先补充一点,为什么苹果会主推N ...
- 按Right-BICEP要求的任务二的测试
测试方法:Right-BICEP 测试计划: 1.Right-结果是否正确? 2.B-是否所有的边界条件都是正确的? 3.P-是否满足性能要求? 4.是否有乘除法? 5.是否有括号? 6.是否有输出方 ...
- 生成Apk遇到的问题
conversion to dalvik format failed with error 1 android proguard keep Parameterized class
- leetcode 239 Sliding Window Maximum
这题是典型的堆排序算法,只是比一般的堆算法多了删除的操作,有两件事需要做: 1 用一个hash表存储从输入数组索引到堆数组(用于实现堆的那个数组)所以的映射,以便在需要删除一个元素的时候能迅速定位到堆 ...
- maven3在eclipse3.4.2中创建java web项目
学习maven时参考的一些的博客地址:http://www.cnblogs.com/fnng/archive/2011/12/16/2290587.htmlhttp://sarin.iteye.com ...