题目:
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 system will match the keywords with description of image and show the image which the most keywords be matched. 
To simplify the problem, giving you a description of image, and some keywords, you should tell me how many keywords will be match. 

InputFirst line will contain one integer means how many cases will follow by. 
Each case will contain two integers N means the number of keywords and N keywords follow. (N <= 10000) 
Each keyword will only contains characters 'a'-'z', and the length will be not longer than 50. 
The last line is the description, and the length will be not longer than 1000000. 
OutputPrint how many keywords are contained in the description.Sample Input

1
5
she
he
say
shr
her
yasherhs

Sample Output

3
题意就是说给你一些模式串,问你有哪几个在目标串中出现过,(⊙o⊙)…,和洛谷那道末班体一模一样,就是多了一个多组数据。
 #include<cstdio>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<cstring>
#include<queue>
using namespace std; int n,cnt=;
char s[];
struct Node
{
int c[],suf,flag;
void init()
{
suf=flag=;
memset(c,,sizeof(c));
}
}tree[]; void init()
{
for (int i=;i<=cnt;i++)
tree[i].init();
cnt=;
}
void Ins()
{
int head=,l=strlen(s);
for (int i=;i<l;i++)
{
int now=s[i]-'a';
if (!tree[head].c[now]) tree[head].c[now]=++cnt;
head=tree[head].c[now];
}
tree[head].flag++;
}
void Make_AC()
{
for (int i=;i<;i++) tree[].c[i]=;
int head=,tail=;
queue<int>q;
while (!q.empty()) q.pop();
tree[].suf=;
q.push();
while (!q.empty())
{
int u=q.front();
q.pop();
for (int i=;i<;i++)
if (tree[u].c[i])
{
tree[tree[u].c[i]].suf=tree[tree[u].suf].c[i];
q.push(tree[u].c[i]);
}
else tree[u].c[i]=tree[tree[u].suf].c[i];
}
}
void Solve()
{
scanf("%s",s);
int ans=,head=,len=strlen(s);
for (int i=;i<len;i++)
{
int now=s[i]-'a';
head=tree[head].c[now];
for (int j=head;j&&tree[j].flag!=-;j=tree[j].suf)
ans+=tree[j].flag,tree[j].flag=-;
}
printf("%d\n",ans);
}
int main()
{
int Cas;
scanf("%d",&Cas);
while (Cas--)
{
init();
scanf("%d",&n);
while (n--){scanf("%s",s);Ins();}
Make_AC();
Solve();
}
}
 

HDU-2222文字检索的更多相关文章

  1. HDU 2222  AC自动机模板题

    1.HDU 2222 2.题意:给出n个单词,一个字串,求有多少个单词在字串里出现了.注意给出的单词可能会重复,重复的不计. 3.总结:入门题.在查询这里还是不太懂. #include<bits ...

  2. HDU 2222 Keywords Search(AC自动机模版题)

    Keywords Search Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others ...

  3. HDU 2222 Keywords Search(查询关键字)

    HDU 2222 Keywords Search(查询关键字) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K ...

  4. HDU 2222 最简单的AC自动机套模板应用

    HDU 2222 题意:给出N(N<=10,000)个单词,每个单词长度不超过50.再给出一个字符串S,字符串长度不超过1,000,000.问有多少个单词出现在了字符串S中.(单词可能重复,单词 ...

  5. HDU 2222 (AC自动机)

    HDU 2222 Keywords search Problem : 给若干个模式串,询问目标串中出现了多少个模式串. Solution : 复习了一下AC自动机.需要注意AC自动机中的fail,和n ...

  6. HDU - 2222,HDU - 2896,HDU - 3065,ZOJ - 3430 AC自动机求文本串和模式串信息(模板题)

    最近正在学AC自动机,按照惯例需要刷一套kuangbin的AC自动机专题巩固 在网上看过很多模板,感觉kuangbin大神的模板最为简洁,于是就选择了用kuangbin大神的模板. AC自动机其实就是 ...

  7. hdu 2222 Keywords Search

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=2222 思路:裸AC自动机,直接贴代码做模板 #include<stdio.h> #includ ...

  8. HDU 2222 AC自动机模板题

    题目: http://acm.hdu.edu.cn/showproblem.php?pid=2222 AC自动机模板题 我现在对AC自动机的理解还一般,就贴一下我参考学习的两篇博客的链接: http: ...

  9. HDU 2222(AC自动机模板题)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2222 题目大意:多个模式串.问匹配串中含有多少个模式串.注意模式串有重复,所以要累计重复结果. 解题 ...

  10. HDU 2222:Keywords Search(AC自动机模板)

    http://acm.hdu.edu.cn/showproblem.php?pid=2222 KMP是单模式串匹配的算法,而AC自动机是用于多模式串匹配的算法.主要由Trie和KMP的思想构成. 题意 ...

随机推荐

  1. 针对通达OA20170729集团版设计门户管理解决方案的具体实例

    随着企业信息化建设的深入,应用系统数量不断增加,应用功能不断丰富,数据信息也在呈几何级数增长,在支撑企业正常工作运转的同时,也衍生出许多新的问题: 通达信科根据自身从业多年的行业实践经验,勇于打破传统 ...

  2. 迁移学习-Transfer Learning

    迁移学习两种类型: ConvNet as fixed feature extractor:利用在大数据集(如ImageNet)上预训练过的ConvNet(如AlexNet,VGGNet),移除最后几层 ...

  3. ★电车难题的n个坑爹变种

    哲学家都不会做的电车难题变异 此题会答清华北大 "电车难题(Trolley Problem)"是伦理学领域最为知名的思想实验之一,其内容大致是: 一个疯子把五个无辜的人绑在电车轨道 ...

  4. px,em,rem的关系

    之前听人说过,网站制作中字体单位应该用em而不用px,为什么呢?原因简单来说就是em支持IE6下的字体缩放,在页面中按ctrl+滚轮,字体以px为单位的网站没有反应.px是绝对单位,不支持IE的缩放, ...

  5. Java 多线程(二) 线程的实现

    线程的实现 在Java中通过run方法为线程指明要完成的任务,有两种技术来为线程提供run方法: 1.继承Thread类并重写它的run方法.之后创建这个子类的对象并调用start()方法. 2.通过 ...

  6. 软工+C(2017第4期) Alpha/Beta换人

    // 上一篇:超链接 // 下一篇:工具和结构化 注:在一次软件工程讨论课程进度设计的过程中,出现了这个关于 Alpha/Beta换人机制的讨论,这个机制在不同学校有不同的实施,本篇积累各方观点,持续 ...

  7. 大家一起来找茬(BUG)

    大家一起来找茬(BUG) ----------目录---------- 一.上手体验 1.主界面 2.功能 二.程序的 BUG 三.必应词典的 BUG 1."每日一句"里的句子不能 ...

  8. 201521123013 《Java程序设计》第8周学习总结

    1. 本章学习总结 2. 书面作业 Q1.List中指定元素的删除(题目4-1) 1.1 实验总结 while(list.contains(str)) list.remove(str); Q2.统计文 ...

  9. 201521123018 《Java程序设计》第1周学习总结

    1. 本章学习总结 *Java程序的特点 *可以跨平台运行 *语言简单 *利用控制台运行java程序 *cmd调出控制台->用javac指令编译源代码->用java指令运行 2. 书面作业 ...

  10. Java-高效地使用Exception-实践

    注:本文翻译自Exceptional practices,共分为3节.该文章从实践的角度非常透彻地解释了为什么要处理异常,以及如何处理异常.这些都是那些只会介绍trycatchfinally语法的教材 ...