【刷题】HDU 2222 Keywords Search】的更多相关文章

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…
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 t…
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…
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…
点击打开链接题目链接 Keywords Search Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 42838    Accepted Submission(s): 13488 Problem Description In the modern time, Search engine came into the life of eve…
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…
http://acm.hdu.edu.cn/showproblem.php?pid=2222 题意:给出多个单词,最后再给出一个模式串,求在该模式串中包含了多少个单词. 思路: AC自动机的模板题. #include<iostream> #include<algorithm> #include<cstring> #include<cstdio> #include<vector> #include<stack> #include<…
单词统计的题目,给出一些单词,统计有多少单词在一个文本中出现,最经典的入门题了. AC自己主动机的基础: 1 Trie. 以这个数据结构为基础的,只是添加一个fail指针和构造fail的函数 2 KMP,不是直接运用KMP.而是须要KMP的思想.KMP思想都没有的话,理解这个算法会更加吃力的. 注意本题的单词会有反复出现的,一个单词仅仅能统计一次. 搜索了一下网上的题解.发现好多代码都是一大抄的啊.⊙﹏⊙b汗. 本博客的乃是原创代码.代码风格也是几乎相同固定的,转载请注明出处:http://bl…
学习AC自动机请戳这里:大神blog........ 自动机的模板: #include <iostream> #include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <string> #include <vector> #include <set> #…
<题目链接> 题目大意: 给你一些单词,和一个字符串,问你这个字符串中含有多少个上面的单词. 解题分析: 这是多模匹配问题,如果用KMP的话,对每一个单词,都跑一遍KMP,那么当单词数量非常多的时候,耗时会非常多,所以这里用到了AC自动机,这是一种类似于Trie树的数据结构,但是同时,它也用到了KMP算法中 next数组的思想. 本题可做模板: #include <bits/stdc++.h> using namespace std; ; ],cnt[N],fail[N],pos;…
题意:给出一个字符串和若干个模板,求出在文本串中出现的模板个数. 思路:由于有可能有反复的模板,trie树权值记录每一个模板出现的次数就可以. #include<cstdio> #include<cstring> #include<cmath> #include<cstdlib> #include<iostream> #include<algorithm> #include<vector> #include<map&…
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 题意:有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自动机,首先利用小字符串建立一个Trie,然后再Trie上做KMP,使得为一个节点具有一个fail指针,其含义是,当文本串在某个节点失配时,则在Trie上找到根节点到这个节点的最长后缀的一个串,然后指向它. 不断地匹配下去就行了. #includ…
题目:http://acm.hdu.edu.cn/showproblem.php?pid=2222 第一道AC自动机! T了无数边后终于知道原来它是把若干询问串建一个自动机,把模式串放在上面跑:而且只走模式串的前缀,用 fail 指针来精准遍历每个前缀的每个后缀,就能行了. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std…
/* 啥也不说了,直接套模板... */ 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…
题意:给你一些模式串,再给你一串匹配串,问你在匹配串中出现了多少种模式串,模式串可以相同 AC自动机:trie树上进行KMP.首先模式串建立trie树,再求得失配指针(类似next数组),其作用就是在这一位不匹配时转移到失配指针上.失配指针是转移到某个等于此位置最长后缀的位置,求法是bfs #include<set> #include<map> #include<queue> #include<stack> #include<cmath> #in…
题意:给你几个keywords,再给你一段文章,问你keywords出现了几次. 思路:这里就要用到多模匹配算法AC自动机了,AC自动机需要KMP和字典树的知识,匹配时是在字典树上,失配我们就要用到类似KMP的失配值了,如果失配,我们就沿着失配值到某个节点开始匹配,因为是多模匹配,我们每次失配移动都会从某一keyword的某部分开始匹配,这样就节省了很多时间. 话说第一次听到AC自动机我竟天真的以为是会自动AC题目的算法...orz 参考: AC自动机算法详解 (转载) ac自动机最详细的讲解,…
题意:给出若干个单词和一段文本,问有多少个单词出现在其中.如果两个单词是相同的,得算两个单词的贡献. 分析:直接就是AC自动机的模板了. 具体见代码: #include <stdio.h> #include <algorithm> #include <string.h> #include <queue> using namespace std; + ; + ; struct Aho { struct state { ]; int fail,cnt; }sta…
题意:就是求目标串中出现了几个模式串. 思路:用int型的end数组记录出现,AC自动机即可. #include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<string> #include<algorithm> #include<queue> #define maxn 500005 int T,n; ]; struct Tri…
题目链接 先整理一发ac自动机模板.. #include <iostream> #include <vector> #include <cstdio> #include <cstring> #include <algorithm> #include <complex> #include <cmath> #include <map> #include <set> #include <string…
询问有多少个模式串出现在了文本串里面.将模式串插入Trie树中,然后跑一边AC自动机统计一下就哦了. 献上一份模板. #include <cstdio> #include <cstring> #include <queue> #define MAX_NODE 240005 #define MAX_CHILD 26 using namespace std; class AC_Automaton { public: int chd[MAX_NODE][MAX_CHILD];…
题目链接 题意:每个文本串的出现次数 分析:入门题,注意重复的关键字算不同的关键字,还有之前加过的清零.   新模板,加上last跑快一倍 #include <bits/stdc++.h> struct AC { static const int NODE = 10000 * 50 + 5; static const int SIZE = 26; int ch[NODE][SIZE], fail[NODE], last[NODE]; int end[NODE]; int sz; void cl…
Keywords Search Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 44687    Accepted Submission(s): 14103 Problem Description In the modern time, Search engine came into the life of everybody li…
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…
Keywords Search Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 59360    Accepted Submission(s): 19520 Problem Description In the modern time, Search engine came into the life of everybody lik…
题目 传送门:QWQ 分析 $ AC $自动机模板,黈力的码风真的棒极了,这是我抄他的. 还有 题号不错 代码 #include <cstdio> #include <cstring> #define N 500007 using namespace std; ],fail[N],cur,j,end[N],q[N],vis[N],ans[N],end2[N],end3[N]; ]; int find(int cur,int i){ if(!cur)return rt; if(son…
[算法]AC自动机 [题解]本题注意题意是多少关键字能匹配而不是能匹配多少次,以及可能有重复单词. 询问时AC自动机与KMP最大的区别是因为建立了trie,所以对于目标串T与自动机串是否匹配只需要直接访问对应结点,而不用真的比较. 因此可以预处理出拥有对应节点的失配串,不用一次一次跑前跑去找一样的. 然后还有就是一个结点可能对应多个串,所以需要last使统计答案完整. AC自动机的细节标注在代码里了. AC自动机过程: [trie] for 长度 if(!ch[u][c])初始化,ch[u][c…
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 find the image, the…