trie字典树
---恢复内容开始---
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1251
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define re register
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define P pair<int,int>
const int N=1e6+;
const int mod=;
void read(int &a)
{
a=;
int d=;
char ch;
while(ch=getchar(),ch>''||ch<'')
if(ch=='-')
d=-;
a=ch-'';
while(ch=getchar(),ch>=''&&ch<='')
a=a*+ch-'';
a*=d;
}
void write(int x)
{
if(x<)
putchar(),x=-x;
if(x>)
write(x/);
putchar(x%+'');
}
int trie[][],len,root,tot,sum[];
bool p;
char s[];
void ins()
{
len=strlen(s);
root=;
for(re int i=;i<len;i++)
{
int id=s[i]-;
if(!trie[root][id])
trie[root][id]=++tot;
root=trie[root][id];
sum[root]++;
}
}
int sear()
{
root=;
len=strlen(s);
for(re int i=;i<len;i++)
{
int id=s[i]-;
if(!trie[root][id])
return ;
root=trie[root][id];
}
return sum[root];
}
int main()
{
int f=;
while(gets(s))
{
if(strlen(s)==)
{
f=;
continue;
}
if(!f)
ins();
else
cout<<sear()<<endl;
}
return ;
}
---恢复内容结束---
trie字典树的更多相关文章
- 萌新笔记——C++里创建 Trie字典树(中文词典)(一)(插入、遍历)
萌新做词典第一篇,做得不好,还请指正,谢谢大佬! 写了一个词典,用到了Trie字典树. 写这个词典的目的,一个是为了压缩一些数据,另一个是为了尝试搜索提示,就像在谷歌搜索的时候,打出某个关键字,会提示 ...
- Trie字典树 动态内存
Trie字典树 #include "stdio.h" #include "iostream" #include "malloc.h" #in ...
- 算法导论:Trie字典树
1. 概述 Trie树,又称字典树,单词查找树或者前缀树,是一种用于快速检索的多叉树结构,如英文字母的字典树是一个26叉树,数字的字典树是一个10叉树. Trie一词来自retrieve,发音为/tr ...
- 标准Trie字典树学习二:Java实现方式之一
特别声明: 博文主要是学习过程中的知识整理,以便之后的查阅回顾.部分内容来源于网络(如有摘录未标注请指出).内容如有差错,也欢迎指正! 系列文章: 1. 标准Trie字典树学习一:原理解析 2.标准T ...
- 817E. Choosing The Commander trie字典树
LINK 题意:现有3种操作 加入一个值,删除一个值,询问pi^x<k的个数 思路:很像以前lightoj上写过的01异或的字典树,用字典树维护数求异或值即可 /** @Date : 2017- ...
- C++里创建 Trie字典树(中文词典)(一)(插入、遍历)
萌新做词典第一篇,做得不好,还请指正,谢谢大佬! 写了一个词典,用到了Trie字典树. 写这个词典的目的,一个是为了压缩一些数据,另一个是为了尝试搜索提示,就像在谷歌搜索的时候,打出某个关键字,会提示 ...
- 数据结构 -- Trie字典树
简介 字典树:又称单词查找树,Trie树,是一种树形结构,是一种哈希树的变种. 优点:利用字符串的公共前缀来减少查询时间,最大限度地减少无谓的字符串比较,查询效率比哈希树高. 性质: 1. 根节 ...
- 踹树(Trie 字典树)
Trie 字典树 ~~ 比 KMP 简单多了,无脑子选手学不会KMP,不会结论题~~ 自己懒得造图了OI WIKI 真棒 字典树大概长这么个亚子 呕吼真棒 就是将读进去的字符串根据当前的字符是什么和所 ...
- trie字典树详解及应用
原文链接 http://www.cnblogs.com/freewater/archive/2012/09/11/2680480.html Trie树详解及其应用 一.知识简介 ...
- Trie字典树 静态内存
静态字典树 看了好久的字典树,挺简单的一个结构,愣是看了这么久才写出来... 专心一点就不会这样了.... 接下来就去刷刷字典树的题吧....... 下面是字典树.... 定义节点 typedef s ...
随机推荐
- simulation vs emulation
Hardware emulation, the use of special purpose hardware to emulate the behavior of a yet-to-be-built ...
- asp:LinkBtton PostBackUrl 中文乱码
这个也不行: HttpUtility.UrlEncode("中文") 替代方案为:<asp:HyperLink NavigateUrl=“~/路径” Target=" ...
- vmware 中安装Ghost XP 版本心得
安装是肯定是选择 ISO映像文件,第一次进入真能进入Ghost选择界面, 无论你第一次 进入的是pe 或 一键分区还是 ghost到C盘最后你再重启就总是让你按任意键或Ctrl+Alt+Del 自然想 ...
- myeclipse编译弹框:The builder launch configuration could not be found
myEclipse 每次编译时报 "The builder launch configuration could not be found" 的弹框:不影响项目编译启动,但是弹框挺 ...
- 树剖+线段树||树链剖分||BZOJ1984||Luogu4315||月下“毛景树”
题面:月下“毛景树” 题解:是道很裸的树剖,但处理的细节有点多(其实是自己线段树没学好).用一个Dfs把边权下移到点权,用E数组记录哪些边被用到了:前三个更新的操作都可以合并起来,可以发现a到b节点间 ...
- Eonasdan bootstrap datetimepicker 使用记录
开始用的 bootstrap日期选择控件是 bootstrap-datepicker : $('#visit_date').datepicker({ todayHighlight: true, sta ...
- Oracle 变量之 DDL_LOCK_TIMEOUT
DDL_LOCK_TIMEOUTProperty DescriptionParameter type IntegerDefault value 0Modifiable ALTER SESSIONRan ...
- event.stopPropagation(),event.preventDefault()和return false的区别
event.stopPropagation(),event.preventDefault()和return false的区别 1.event.stopPropagation()方法 这是阻止事件的冒泡 ...
- arcengine直连sde
搞了半天,找了好多资料,实验好多次,终于解决.参考资料:http://www.cnblogs.com/gaxin/p/5777864.html
- Uniform Resource Name Server
HTTP The Definitive Guide 按址标识 identify by address 按名标识 identify by name Domain Name Server Uniform ...