Keywords Search

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 35683    Accepted Submission(s): 11520

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
 
代码:
 
字典树
 /*hdu 2222 字典树*/
//#define LOCAL
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
struct Trie
{
struct Trie *next[];
int tail;
};
char str[];
char ss[];
void in_Trie(char *s,Trie *root)
{
Trie *cur=root,*newcur;
for(int i=;s[i]!='\0';i++)
{
if(cur->next[s[i]-'a']==NULL)
{
newcur=new Trie; //(Trie*)malloc(sizeof(sizeof(Trie)));
for(int j=;j<;j++)
newcur->next[j]=NULL;
newcur->tail=;
cur->next[s[i]-'a']=newcur;
}
cur=cur->next[s[i]-'a'];
}
cur->tail++;
}
int query(char *s,Trie *root)
{
int i=,cnt=;
Trie *cur;
for(int j=;s[j]!='\0';j++)
{
cur=root;
for(i=j;s[i]!='\0';i++){
if(cur->next[s[i]-'a']!=NULL){
cur=cur->next[s[i]-'a'];
cnt+=cur->tail;
cur->tail=; //只需求出第一次出现的
}
else break;
}
}
return cnt;
}
void dele(Trie *root)
{
for(int i= ; i< ; i++ )
if(root->next[i]!=NULL)
dele(root->next[i]);
// free(root);
delete root;
}
int main()
{
#ifdef LOCAL
freopen("test.in","r",stdin);
#endif
int t,i,n;
Trie *root;
scanf("%d",&t);
while(t--)
{
root = new Trie ;
for(int j=;j<;j++)
root->next[j]=NULL;
root->tail=;
scanf("%d",&n);
for(i=;i<n;i++){
scanf("%s",str);
in_Trie(str,root);
}
scanf("%s",ss);
printf("%d\n",query(ss,root));
dele(root);
}
return ;
}

hdu----(2222)Keywords Search(trie树)的更多相关文章

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

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

  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 (AC自动机)

    题意:给你一些模式串,再给你一串匹配串,问你在匹配串中出现了多少种模式串,模式串可以相同 AC自动机:trie树上进行KMP.首先模式串建立trie树,再求得失配指针(类似next数组),其作用就是在 ...

  4. HDU 2222 Keywords Search(瞎搞)

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

  5. hdu 2222 Keywords Search(AC自动机)

    /* 啥也不说了,直接套模板... */ 1 #include<iostream> #include<map> #include<string> #include& ...

  6. hdu 2222 Keywords Search ac自己主动机

    点击打开链接题目链接 Keywords Search Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Ja ...

  7. HDU 2222 Keywords Search (AC自动机)(模板题)

    <题目链接> 题目大意: 给你一些单词,和一个字符串,问你这个字符串中含有多少个上面的单词. 解题分析: 这是多模匹配问题,如果用KMP的话,对每一个单词,都跑一遍KMP,那么当单词数量非 ...

  8. HDU 2222 Keywords Search(AC自己主动机模板题)

    题意:给出一个字符串和若干个模板,求出在文本串中出现的模板个数. 思路:由于有可能有反复的模板,trie树权值记录每一个模板出现的次数就可以. #include<cstdio> #incl ...

  9. hdu 2222 Keywords Search 模板题

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

随机推荐

  1. 3d中的坐标系的概念

    世界坐标系 世界坐标系是一个特殊的坐标系,它建立了描述其它坐标系所需要的参考框架.从另一方面说能够用世界坐标描述其它坐标系的位置,而不能用更大的.外部的坐标系来描述世界坐标系. 物体坐标系 物体坐标系 ...

  2. 获取DIV与浏览器顶部相聚一定位置之后移动DIV

    获取元素(这里定位元素A)距离顶部的高度,接着设定scroll滚动的事件,比如超过那个高度,把A的位置设定为fixed,小于该高度,修改回relative. 方法一: $(function() {  ...

  3. [SAP ABAP开发技术总结]动态修改选择屏幕

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  4. CUBRID学习笔记 2 安装教程

    下载地址  http://www.cubrid.org/?mid=downloads&item=any&os=detect&cubrid=9.3.0 选择适合你的服务器版本 l ...

  5. poj 1410 线段相交判断

    http://poj.org/problem?id=1410 Intersection Time Limit: 1000MS   Memory Limit: 10000K Total Submissi ...

  6. Comware 架构理解

    网络操作系统 首先什么是网络操作系统: 一种说法是:运行在路由器,网络交换机,防火墙上的特别的操作系统 另一种说法是:部署在局域网或者私有网络,允许网络中的多个计算机共享文件和打印机,因为现在的单机系 ...

  7. hdu 3535 AreYouBusy 分组背包

    AreYouBusy Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Probl ...

  8. HDU 5929 Basic Data Structure 模拟

    Basic Data Structure Time Limit: 7000/3500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Oth ...

  9. 跨代的对决 英特尔i7-6700HQ对比i7-4720HQ性能测试

    http://itianti.sinaapp.com/index.php/cpu 跨代的对决 英特尔i7-6700HQ对比i7-4720HQ性能测试 2015-10-13 19:46:31 来源:电脑 ...

  10. 超实用压力测试工具-ab工具

    在学习ab工具之前,我们需了解几个关于压力测试的概念 吞吐率(Requests per second)概念:服务器并发处理能力的量化描述,单位是reqs/s,指的是某个并发用户数下单位时间内处理的请求 ...