HDU 1618 Oulipo KMP解决问题的方法
鉴于两个字符串,寻找一个字符串的频率,另一个字符串出现。
原版的kmp另一个陷阱。以下凝视了,标不是踩着好,有加班一定几率,也有机会错误,根据不同的字符串可以是详细。
变化看起来像一个,kmp速度是非常快的。
#include <stdio.h>
#include <string.h> const int MAX_TXT = 1000001;
const int MAX_WORD = 10001;
int gWlen, gTlen;
char word[MAX_WORD];
int next[MAX_WORD];
char txt[MAX_TXT]; void getNext()
{
memset(next, 0, sizeof(int) * gWlen);
for (int i = 1, j = 0; i < gWlen; )
{
if (word[i] == word[j]) next[i++] = ++j;
else if (j > 0) j = next[j-1];
else i++;
}
} int kmpSearch()
{
int i = 0, j = 0, ans = 0;
for (; gWlen-j <= gTlen-i; )
{
if (word[j] == txt[i])
{
j++; i++;
if (j == gWlen)
{
ans++;
j = next[j-1];
}
//else i++; i++放这里会超时,是一定几率会出现超时。注意了!
}
else if (j > 0) j = next[j-1];
else i++;
}
return ans;
} int main()
{
int T;
scanf("%d", &T);
getchar();
while (T--)
{
gets(word);
gWlen = strlen(word);
gets(txt);
gTlen = strlen(txt); getNext();
printf("%d\n", kmpSearch());
}
return 0;
}
版权声明:笔者靖心脏,景空间地址:http://blog.csdn.net/kenden23/。只有经过作者同意转载。
HDU 1618 Oulipo KMP解决问题的方法的更多相关文章
- HDU - 1686 Oulipo KMP匹配运用
id=25191" target="_blank" style="color:blue; text-decoration:none">HDU - ...
- HDU 1867 A + B for you again KMP解决问题的方法
这是一个典型问题KMP申请书. 结果求增加两个字符串.该法的总和是相同的前缀和后缀也是字符串的字符串,您将可以合并本节. 但是,这个问题是不是问题非常明确的含义,因为不是太清楚,外观这两个字符串的顺序 ...
- hdu 1686 Oulipo KMP匹配次数统计
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1686 分析:典型的KMP算法,统计字符串匹配的次数. 用Next数组压缩时间复杂度,要做一些修改. / ...
- HDU 1686 - Oulipo - [KMP模板题]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1686 Time Limit: 3000/1000 MS (Java/Others) Memory Li ...
- hdu 1686 Oulipo kmp算法
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1686 题目: Problem Description The French author George ...
- POJ 3450 Corporate Identity KMP解决问题的方法
这个问题,需要一组字符串求最长公共子,其实灵活运用KMP高速寻求最长前缀. 请注意,意大利愿父亲:按照输出词典的顺序的规定. 另外要提醒的是:它也被用来KMP为了解决这个问题,但是很多人认为KMP使用 ...
- hdu 1686 Oulipo (kmp)
Problem Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, w ...
- HDU 1686 Oulipo (KMP 可重叠)
题目链接 Problem Description The French author Georges Perec (1936–1982) once wrote a book, La dispariti ...
- 洛谷 P3375 【模板】KMP字符串匹配 || HDU 1686 Oulipo || kmp
HDU-1686 P3375 kmp介绍: http://www.matrix67.com/blog/archives/115 http://www.cnblogs.com/SYCstudio/p/7 ...
随机推荐
- php语法同java语法的基本区别(实例项目需求,php才能熟)
php语法同java语法的基本区别(实例项目需求,php才能熟) 一.总结 看下面 二.PHP基本语法以及和Java的区别 .表示字符串相加 ->同Java中的. $作为变量的前缀,除此之外,变 ...
- HDU 1496 Equations hash HDU上排名第一!
看题传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1496 题目大意: 给定a,b,c,d.a*x1^2+b*x2^2+c*x3^2+d*x4^2=0 ...
- [Angular Unit Testing] Debug unit testing -- component rendering
If sometime you want to log out the comonent html to see whether the html render correctly, you can ...
- [MobX] MobX fundamentals: deriving computed values and managing side effects with reactions
Derivations form the backbone of MobX and come in two flavors: computed values are values that can b ...
- 用Apache Ivy实现项目里的依赖管理 分类: C_OHTERS 2014-07-06 18:11 564人阅读 评论(0) 收藏
Apache Ivy是一个管理项目依赖的工具. 它与Maven Apache Maven 构建管理和项目管理工具已经吸引了 Java 开发人员的注意.Maven 引入了 JAR 文件公共存储库的概念 ...
- 定位导致物化视图无法快速刷新的原因 分类: H2_ORACLE 2013-08-08 23:04 335人阅读 评论(0) 收藏
转载自:http://yangtingkun.itpub.net/post/468/13318 物化视图的快速刷新采用了增量的机制,在刷新时,只针对基表上发生变化的数据进行刷新.因此快速刷新是物化视图 ...
- jquery插件课程2 放大镜、多文件上传和在线编辑器插件如何使用
jquery插件课程2 放大镜.多文件上传和在线编辑器插件如何使用 一.总结 一句话总结:插件使用真的还是比较简单的,引包,初始化,配置参数(json),配置数据(json),而后两步不是必须的.而且 ...
- C#中使用split分割字符串的几种方法小结
1.用字符串分隔: using System.Text.RegularExpressions;string str="aaajsbbbjsccc";string[] sArray= ...
- PatentTips - Method and system for browsing things of internet of things on ip using web platform
BACKGROUND The following disclosure relates to a method and system for enabling a user to browse phy ...
- ios开发利用AFN检测网络状态
AFNetworkReachabilityManager *manager = [AFNetworkReachabilityManager sharedManager]; [manager setRe ...