博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[HDU2222] Keywords Search
阅读量:6153 次
发布时间:2019-06-21

本文共 1836 字,大约阅读时间需要 6 分钟。

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

Total Submission(s): 63773    Accepted Submission(s): 21193

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 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.
 

Input

First 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.

Output

Print how many keywords are contained in the description.
 

Sample Input

1 5 she he say shr her yasherhs

Sample Output

3
 
Recommend
lcy   |   We have carefully selected several similar problems for you:          
 

思路

AC自动机
构建trie树,加上fail指针,就是一个AC自动机了。

代码实现

1 #include
2 #include
3 const int size=3e5+1; 4 const int maxl=1e6+1; 5 int test,n,a,sz,ans; 6 struct nate{
int n[26],f,v;}t[size]; 7 char ch[maxl]; 8 void ins(){ 9 scanf("%s",ch);10 for(int i=0,j=0;;i++){11 if(!ch[i]){t[j].v++;break;}12 a=ch[i]-'a';13 if(!t[j].n[a]) t[j].n[a]=++sz;14 j=t[j].n[a];15 }16 }17 int q[size],head,tail;18 void build(){19 head=tail=0;20 for(int i=0;i<26;i++) q[tail++]=t[0].n[i];21 while(head

 

转载于:https://www.cnblogs.com/J-william/p/7163104.html

你可能感兴趣的文章
Android与html5交互 -- WebView使用(一)
查看>>
体验VS2015 Update 2 的 Android 和 Python
查看>>
ubuntu16.04 Docker默认存储路径修改
查看>>
jQuery 复选框全选反选
查看>>
py5.21
查看>>
将数据导出Excel格式
查看>>
[css3]跑马灯
查看>>
shell面试题整理
查看>>
php函数总结
查看>>
Java 对象的封装,继承,抽象,接口写法
查看>>
Java抽象类与接口的区别
查看>>
换教室
查看>>
Oracle笔记(4):一个存储过程编写及C#调用
查看>>
第二轮冲次会议第二次
查看>>
第二阶段评分
查看>>
QQ在线客服不用加好友就可聊天
查看>>
mysql 操作符
查看>>
编写一个Java程序,计算半径为3.0的圆周长和面积并输出结果
查看>>
大道甚夷,而人好径
查看>>
Christopher Steiner:算法如何改变了世界
查看>>