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叉树. 我理解字典树是看了这位大佬博客.还不了解字典树的 ...
随机推荐
- 实例对比 Julia, R, Python,谁是狼语言?
对于一个平台来说,使用者对技术本身是不敏感的,所以我们需要增加一些限制来减少集群的一些不可控情况,例如不断的写入新表/新数据却不记得删除,大量不按规范创建的表名等情况.与此同时应尽量让技术对用户透明, ...
- 个人环境搭建——版本控制SVN
版本控制SVN SVN服务器配置: 第一部分:svn服务器搭建(主要是四步走) 参考:http://www.son1c.cn/show/920.html 一,安装Subversion sudo apt ...
- bzoj2115【WC2011】XOR
题意:http://www.lydsy.com/JudgeOnline/problem.php?id=2115 sol :首先考虑处理出DFS树,那么树上的所有非树边可以构成一个简单环 因为所有不在 ...
- 【CCF】除法 树状数组
[AC] #include<iostream> #include<math.h> #include<cstring> using namespace std; ty ...
- hdu 1423 最长上升递增子序列
#include <iostream> #include <cstdio> #include <cstring> using namespace std; ; in ...
- *LOJ#2306. 「NOI2017」蔬菜
$n \leq 100000$种蔬菜,每个蔬菜有:一单位价格:卖第一单位时额外价格:总量:每天腐烂量.每天能卖$m \leq 10$单位蔬菜,多次询问:前$k \leq 100000$天最多收入多少. ...
- [LeetCode] Search Insert Position 二分搜索
Given a sorted array and a target value, return the index if the target is found. If not, return the ...
- [LeetCode] Maximum Depth of Binary Tree dfs,深度搜索
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...
- 高级参数绑定(数组和List绑定)
1.绑定数组: (1) 需求 在商品列表页面选中多个商品,然后删除. (2). 需求分析 功能要求商品列表页面中的每个商品前有一个checkbok,选中多个商品后点击删除按钮把商品id传递给Contr ...
- APP漏洞扫描用地址空间随机化【转】
转自:http://www.cnblogs.com/alisecurity/p/6141575.html 前言 我们在前文<APP漏洞扫描器之本地拒绝服务检测详解>了解到阿里聚安全漏洞扫描 ...