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

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

Keywords Search

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 47635    Accepted Submission(s): 15167


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
 

Author
Wiskey
 

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

#include
#include
#include
#include
#include
#include
#include
#define F(i,j,n) for(int i=j;i<=n;i++)#define D(i,j,n) for(int i=j;i>=n;i--)#define ll long long#define pa pair
#define maxn 500005using namespace std;int tt,n,ans,tot;int t[maxn][26],go[maxn],v[maxn];bool used[maxn];char s[1000005];inline void insert(){ scanf("%s",s); int len=strlen(s),now=1; F(i,0,len-1) { int x=s[i]-'a'; if (!t[now][x]) t[now][x]=++tot; now=t[now][x]; } v[now]++;}inline void bfs(){ queue
q; q.push(1); while (!q.empty()) { int x=q.front(),y,j;q.pop(); F(i,0,25) { j=go[x]; while (j&&!t[j][i]) j=go[j]; if (t[x][i]) { go[y=t[x][i]]=j?t[j][i]:1; q.push(y); } else t[x][i]=j?t[j][i]:1; } }}inline void calc(int j){ while (j&&!used[j]) { if (v[j]) ans+=v[j]; used[j]=true; j=go[j]; }}inline void find(){ int len=strlen(s),j=1; F(i,0,len-1) { int x=s[i]-'a'; j=t[j][x]; calc(j); }}int main(){ scanf("%d",&tt); while (tt--) { tot=1;ans=0; memset(t,0,sizeof(t)); memset(v,0,sizeof(v)); memset(go,0,sizeof(go)); memset(used,false,sizeof(used)); scanf("%d",&n); F(i,1,n) insert(); bfs(); scanf("%s",s); find(); printf("%d\n",ans); }}

转载地址:http://teesl.baihongyu.com/

你可能感兴趣的文章
Ubuntu 上 执行命令 java -version 显示 没有那个文件或目录
查看>>
jQuery补充之jQuery扩展/form表单提交/滚动菜单
查看>>
Html5拖拽复制
查看>>
RDLC报表格式化format表达式
查看>>
ArcMap属性的列菜单简介
查看>>
【2011.9.20】基于CXF Web Service:Apache CXF简单部署 .
查看>>
jquery Flexigrid的使用
查看>>
Inotify + rsync
查看>>
中风从水治案
查看>>
SQL Server 内存使用量下降问题
查看>>
嵌入式驱动开发之dsp fpga通信接口---spi串行外围接口、emif sram接口
查看>>
网络协议之socks---子网和公网的穿透
查看>>
Java控制语句——if语句
查看>>
BadUSB的防范研究
查看>>
网站flash黑屏问题
查看>>
JAVA TIMER定时器
查看>>
CCF-201512-3 绘图
查看>>
测试了一下LINQ写的Quick Sort性能
查看>>
网站是否有播放音乐功能
查看>>
架构设计:远程调用服务架构设计及zookeeper技术详解(上篇)
查看>>