HDU 2222 关键词查找】的更多相关文章

题目大意:给出一篇文章,长度最多1000000,若干个关键词,关键词有可能重复.关键词不超过10000,每个关键词不超过50个字符.请问该文章包含多少个关键词. 这是AC自动机的入门题.首先将关键词分别插入到一棵trie树中,对每个关键词的对应的结束节点设置一个标记:第二步设置trie树中节点的fail指针.每个节点u都得有fail指针,指向某一个节点v,表示当u无法继续往下匹配时,u应该跳转的节点.节点u与v的字符相同,且根到v的字符串为根到u的字符串的最长后缀.如果u没有找到对应的v,则u的…
1.HDU 2222 2.题意:给出n个单词,一个字串,求有多少个单词在字串里出现了.注意给出的单词可能会重复,重复的不计. 3.总结:入门题.在查询这里还是不太懂. #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define F(i,a,b) for (int i=a;i<b;i++) #define FF(i,a…
Keywords Search Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 57353    Accepted Submission(s): 18820 Problem Description In the modern time, Search engine came into the life of everybody li…
HDU 2222 Keywords Search(查询关键字) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) [Description] [题目描述] In the modern time, Search engine came into the life of everybody like Google, Baidu, etc. Wiskey also wants to br…
VC模拟发送数据包-百度关键词查找 逗比汪星人2009-09-06上传   VC模拟发送数据包-百度关键词abcdef查找 详情 http://blog.csdn.net/wangningyu http://download.csdn.net/detail/wangningyu/1637723…
HDU 2222 题意:给出N(N<=10,000)个单词,每个单词长度不超过50.再给出一个字符串S,字符串长度不超过1,000,000.问有多少个单词出现在了字符串S中.(单词可能重复,单词在S中允许重叠) 我们在val[]数组中记录重复的个数 因为在主串对他进行匹配时,匹配到一次后这个重复次数就不应该继续添加了,所以在query中val[]要对它进行清零操作 #include <cstdio> #include <cstring> #include <queue&…
HDU 2222 Keywords search Problem : 给若干个模式串,询问目标串中出现了多少个模式串. Solution : 复习了一下AC自动机.需要注意AC自动机中的fail,和next的含义.fail指向了一个最长的与当前匹配出具有相同后缀的一个前缀节点,next用来转移下一个字符,指向最远可以匹配的位置.另外,在目标串匹配时,需要用一个temp指针不断经过fail指针向前跳转,所有经过的节点都是符合的. #include <iostream> #include <…
最近正在学AC自动机,按照惯例需要刷一套kuangbin的AC自动机专题巩固 在网上看过很多模板,感觉kuangbin大神的模板最为简洁,于是就选择了用kuangbin大神的模板. AC自动机其实就是字典树和KMP的结合,然后去思考一下KMP的原理,然后就是在字典树上实现KMP 这里最重要的思想可能就是fail的思想,就像KMP一样,匹配失败后,有一个next的数组去回溯(最长公共前缀后缀) 如何理解了KMP的话,感觉这个不会很难理解,字典树是一个非常简单的东西就不用讲了吧. HDU - 222…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2222 题意:有N(N <= 10000)个长度不超过50的模式串和一个长度不超过1e6的文本串.其中模式串可以重复.问有多少文本串在模式串中出现过.(对于相同的模式串次数仍然累加) 思路:ac自动机裸题: KMP是先将文本串进行匹配得到失配边f[];但是并不适用于文本串较长,模式串较多的情况.因为每次查询的时间复杂度为O(n+m).n,m分别为文本串和模式串的长度: ac自动机就是建立在Trie上,…
链接:http://acm.hdu.edu.cn/showproblem.php?pid=2222 思路:裸AC自动机,直接贴代码做模板 #include<stdio.h> #include<string.h> #include<malloc.h> #include<queue> using namespace std; +]; struct node { int count; ]; struct node *fail; void init() { int…
题目: http://acm.hdu.edu.cn/showproblem.php?pid=2222 AC自动机模板题 我现在对AC自动机的理解还一般,就贴一下我参考学习的两篇博客的链接: http://blog.csdn.net/niushuai666/article/details/7002823 http://www.cppblog.com/menjitianya/archive/2014/07/10/207604.html #include<stdio.h> #include<s…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2222 题目大意:多个模式串.问匹配串中含有多少个模式串.注意模式串有重复,所以要累计重复结果. 解题思路: AC自动机模板题. 一开始使用LRJ的坑爹静态模板,不支持重复的模式串. 在做AC自动机+DP的时候,扒了zcwwzdjn大神的动态优化(失配指向root)写法,以及借鉴了网上的AC自动机模板, 搞出了这么一个支持重复串的模板. 注意在计算last后缀链接的时候,都会修改last->cnt=…
http://acm.hdu.edu.cn/showproblem.php?pid=2222 KMP是单模式串匹配的算法,而AC自动机是用于多模式串匹配的算法.主要由Trie和KMP的思想构成. 题意:输入N个模式串,再给出一个文本串,求文本串里出现的模式串数目. #include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <algorithm>…
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 51758    Accepted Submission(s): 16671 Problem Description In the modern time, Search engine came into the life of everybody like Google, Baidu,…
http://acm.hdu.edu.cn/showproblem.php?pid=2222 题意:给出多个单词,最后再给出一个模式串,求在该模式串中包含了多少个单词. 思路: AC自动机的模板题. #include<iostream> #include<algorithm> #include<cstring> #include<cstdio> #include<vector> #include<stack> #include<…
题目链接:[http://acm.hdu.edu.cn/showproblem.php?pid=2222] 题意:给出很多小字符串,然后给出一个文本串,问文本串中包含多少个小字符串.也就是说如果文本串中出现了多次某个小字符串,则只算一次. 题解:裸的AC自动机,首先利用小字符串建立一个Trie,然后再Trie上做KMP,使得为一个节点具有一个fail指针,其含义是,当文本串在某个节点失配时,则在Trie上找到根节点到这个节点的最长后缀的一个串,然后指向它. 不断地匹配下去就行了. #includ…
http://acm.split.hdu.edu.cn/showproblem.php?pid=2222 #include <cstdio> #include <cstdlib> #include <cstring> + ; ; struct AC { int son[maxn][N], fail[maxn * N], endPos[maxn * N]; int t, root; int create() { ++t; ; i < N; ++i) son[t][i…
题目:http://acm.hdu.edu.cn/showproblem.php?pid=2222 第一道AC自动机! T了无数边后终于知道原来它是把若干询问串建一个自动机,把模式串放在上面跑:而且只走模式串的前缀,用 fail 指针来精准遍历每个前缀的每个后缀,就能行了. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std…
Keywords Search Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 35655    Accepted Submission(s): 11496 Problem Description In the modern time, Search engine came into the life of everybody like…
参考iwtwiioi的模板写出来的.上午gty讲的并没有听懂,只好自己慢慢对着模板理解. 在HDU上为什么相同的程序提交有时T有时A!!! 奉上sth神犇的模板(不是这道题): var ch:char; q,g,num:array [0..500001] of longint; st:string; son:array [0..500001,'a'..'z'] of longint; ts:array [0..1000001] of char; l,s,t,n,i,j,m,k,ans,head,…
题目大意:输入几个子串,然后输入一个母串,问在母串里面包含几个子串.   分析:刚学习的AC自动机,据说这是个最基础的模板题,所以也是用了最基本的写法来完成的,当然也借鉴了别人的代码思想,确实是个很神奇的东西,如果不懂KMP的话,最好先学学KMP再来学这个,会理解的更深刻一些.   代码如下: ======================================================================================================…
2222 思路: ac自动机模板题: 代码: #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define maxn 500005 struct TreeNodeType { int count; TreeNodeType *fail; TreeNodeType *next[]; TreeNodeType()…
Keywords Search Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 50451    Accepted Submission(s): 16236 Problem Description In the modern time, Search engine came into the life of everybody lik…
Keywords Search Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 85068    Accepted Submission(s): 29646 Problem Description In the modern time, Search engine came into the life of everybody lik…
t n个字串 1个母串 求出现几个字串 字串可能重复 #include<stdio.h> #include<algorithm> #include<string.h> #include<queue> using namespace std; class node { public: int mark; node *fail; node * next[]; node() { mark=; fail=; memset(next,,sizeof(next)); }…
/* 啥也不说了,直接套模板... */ 1 #include<iostream> #include<map> #include<string> #include<cstring> #include<queue> #define N 500000 using namespace std; class AC_Atomata { public: int nodeN;//trie树的节点个数 ];//trie树 int f[N];//失配函数 //ma…
题意:给出n个单词,一篇文章,询问有几个单词在文章中出现过. /* AC自动机的裸题. 题目标号牛的一比. */ #include<cstdio> #include<cstring> #include<iostream> #define N 500010 #define M 1000010 using namespace std; ],danger[N],point[N],mark[N],q[N],n,size; char ch[M]; void insert(){ ;…
Problem Description In the modern time, Search engine came into the life of everybody like Google, Baidu, etc.Wiskey also wants to bring this feature to his image retrieval system.Every image have a long description, when users type some keywords to…
多模匹配 题目大意:给定很多个字串A,B,C,D,E....,然后再给你目标串str字串,看目标串中出现多少个给定的字串. 经典AC自动机模板题,不多说. #include <iostream> #include <algorithm> #include <functional> #include <string.h> #define MAX 26 using namespace std; struct node { node *fail, *next[MA…
题意:给你一些模式串,再给你一串匹配串,问你在匹配串中出现了多少种模式串,模式串可以相同 AC自动机:trie树上进行KMP.首先模式串建立trie树,再求得失配指针(类似next数组),其作用就是在这一位不匹配时转移到失配指针上.失配指针是转移到某个等于此位置最长后缀的位置,求法是bfs #include<set> #include<map> #include<queue> #include<stack> #include<cmath> #in…