hdu2222Keywords Search字典树入门……
#include<iostream>
#include<cstring>
using namespace std;
struct node
{
int num;
node *next[26];
}*root;
void join(const char *s)
{
node *p=root,*t;
int i,len=strlen(s);
for(i=0;i<len;i++)
if(p->next[s[i]-'a'])
p=p->next[s[i]-'a'];
else
{
t=new node;
memset(t,0,sizeof(node));
p->next[s[i]-'a']=t;
p=t;
}
p->num++;
}
void work(const char *s)
{
node *p;
int i,j,len=strlen(s),sum=0;
for(i=0;i<len;i++)
{
p=root;
for(j=i;j<len;j++)
{
if(p->next[s[j]-'a'])
{
p=p->next[s[j]-'a'];
sum+=p->num;
p->num=0;
}
else
break;
}
}
printf("%d\n",sum);
}
void init()
{
int num;
char t[60];
root=new node;
memset(root,0,sizeof(node));
scanf("%d",&num);
while(num--)
{
scanf("%s",t);
join(t);
}
}
int main()
{
int exp;
char t[1000010];
scanf("%d",&exp);
while(exp--)
{
init();
scanf("%s",t);
work(t);
}
}
hdu2222Keywords Search字典树入门……的更多相关文章
- HDU 1251 统计难题(字典树入门模板题 很重要)
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submi ...
- HDU 5687 字典树入门
Problem C Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total ...
- ACM之路(15)—— 字典树入门练习
刷的一套字典树的题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=120748#overview 个人喜欢指针的字典树写法,但是大力 ...
- hdu 1251 统计难题 (字典树入门题)
/******************************************************* 题目: 统计难题 (hdu 1251) 链接: http://acm.hdu.edu. ...
- HDU 4825 Xor Sum(01字典树入门题)
http://acm.hdu.edu.cn/showproblem.php?pid=4825 题意: 给出一些数,然后给出多个询问,每个询问要从之前给出的数中选择异或起来后值最大的数. 思路:将给出的 ...
- hdu 1247 (字典树入门)
Hat’s Words Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- [ACM] hdu 1251 统计难题 (字典树)
统计难题 Problem Description Ignatius近期遇到一个难题,老师交给他非常多单词(仅仅有小写字母组成,不会有反复的单词出现),如今老师要他统计出以某个字符串为前缀的单词数量(单 ...
- HDU 1251 统计难题(字典树模板题)
http://acm.hdu.edu.cn/showproblem.php?pid=1251 题意:给出一些单词,然后有多次询问,每次输出以该单词为前缀的单词的数量. 思路: 字典树入门题. #inc ...
- 数据结构~trie树(字典树)
1.概述 Trie树,又称字典树,单词查找树或者前缀树,是一种用于快速检索的多叉树结构,如英文字母的字典树是一个26叉树,数字的字典树是一个10叉树. 我理解字典树是看了这位大佬博客.还不了解字典树的 ...
随机推荐
- eslint规范项目代码
安装一系列eslint插件后,填写eslint配置,配置如下 .editorconfig root = true [*] charset = utf-8 indent_style = space in ...
- BZOJ 1975 魔法猪学院(A*+手写堆)
1975: [Sdoi2010]魔法猪学院 Time Limit: 10 Sec Memory Limit: 64 MB Submit: 1941 Solved: 595 [Submit][Sta ...
- python(5)-- 函数
python 函数 定义:函数是组织好的,可重复使用的,用来实现单一,或相关联功能的代码段. 使用好处:函数能提高应用的模块性,和代码的重复利用率. 分类:(1)python 内建函数:pytho ...
- pat 甲级 1009. Product of Polynomials (25)
1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...
- a kind of async programming in c#, need to reference definition
void Main() { Run d=new Run(RunHandler); IAsyncResult result= d.BeginInvoke(new AsyncCallback(CallBa ...
- hdu 5685(逆元)
Problem A Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total S ...
- LeetCode OJ--Word Break II ***@
https://oj.leetcode.com/problems/word-break-ii/ class Solution { public: unordered_set<string> ...
- 【原创】Word2010 清除样式
使用场景 有时候我们在网页上面粘贴一些精华文章或者从去整理别人已经完成的word的时候,会发现它自带的格式,可能并不是我们所理想的格式,所以此时就不得不去重新编辑其格式,但是word里 ...
- Codeforces 785D Anton and School - 2(推公式+乘法原理+组合数学)
题目链接 Anton and School - 2 对于序列中的任意一个单括号对(), 左括号左边(不含本身)有a个左括号,右括号右边(不含本身有)b个右括号. 那么答案就为 但是这样枚举左右的()的 ...
- 基于ARP的网络扫描工具netdiscover
基于ARP的网络扫描工具netdiscover ARP是将IP地址转化物理地址的网络协议.通过该协议,可以判断某个IP地址是否被使用,从而发现网络中存活的主机.Kali Linux提供的netdi ...