hdu1251统计难题(trie)
统计难题
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)
Total Submission(s): 41046 Accepted Submission(s):
14830
注意:本题只有一组测试数据,处理到文件结束.
band
bee
absolute
acm
ba
b
band
abc
3
1
0
#include<cstdio>
#include<cstring>
const int MAXN = ; struct Trie
{
int ch[MAXN][];
int val[MAXN];
int size;//节点总数
void Clear()
{
size = ;
memset(ch[],,sizeof(ch[]));
memset(val,,sizeof(val));
}
int idx(char c)
{
return c - 'a'; //字符c的编号
}
void Insert(const char*s)
{
int u = , len = strlen(s);
for (int i=; i<len; ++i)
{
int c = idx(s[i]);
if (!ch[u][c])
{
memset(ch[size],,sizeof(ch[size]));
ch[u][c] = size++;
}
u = ch[u][c];
val[u]++;
}
}
int Find(const char* s)
{
int u = , len = strlen(s);
for (int i=; i<len; ++i)
{
int c = idx(s[i]);
if (!ch[u][c]) return ;
u = ch[u][c];
}
return val[u] ;
}
}t; int main()
{
char word[];
t.Clear();
while (gets(word)&&strcmp(word,""))
{
t.Insert(word);
}
while (scanf("%s",word)!=EOF)
printf("%d\n",t.Find(word));
return ;
}
hdu1251统计难题(trie)的更多相关文章
- HDU1251 统计难题 Trie树
题目很水,但毕竟是自己第一道的Trie,所以还是发一下吧.Trie的更多的应用慢慢学,AC自动机什么的也慢慢学.... #include<iostream> #include<cst ...
- [hdu1251]统计难题(trie模板题)
题意:返回字典中所有以测试串为前缀的字符串总数. 解题关键:trie模板题,由AC自动机的板子稍加改造而来. #include<cstdio> #include<cstring> ...
- HDU1251 统计难题 trie树 简单
http://acm.hdu.edu.cn/showproblem.php?pid=1251 题意: 找前缀数量 裸模板 #include<cstdio> #include<cstr ...
- HDU1251统计难题---Trie Tree
map巧过 #include <stdio.h> #include <string.h> #include <map> #include <string> ...
- HDU1251 统计难题(Trie)
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others) Total Subm ...
- HDU1251 统计难题 【trie树】
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others) Total Subm ...
- hdu1251 统计难题
地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=1251 题目: 统计难题 Time Limit: 4000/2000 MS (Java/Othe ...
- hdu 1251 统计难题 trie入门
统计难题 Problem Description Ignatius最近遇到一个难题,老师交给他很多单词(只有小写字母组成,不会有重复的单词出现),现在老师要他统计出以某个字符串为前缀的单词数量(单词本 ...
- HDU 1251 统计难题(Trie)
统计难题 [题目链接]统计难题 [题目类型]Trie &题解: Trie的模板题,只不过这题坑点在没给数据范围,改成5e5就可以过了,用的刘汝佳蓝书模板 &代码: #include & ...
随机推荐
- 聪明的Azure CDN,帮你找到云端捷径
你知道吗?身处上海和纽约的两个用户同时通过网络收看“春晚”直播,纽约播放得可能比上海还要更流畅,这当然不是因为纽约距离北京的直播机房更近或者网速更快,而是因为大年夜在大洋彼岸围观“春晚”的观众相对较少 ...
- Apache Module mod_ssl
http://httpd.apache.org/docs/current/mod/mod_ssl.html Description: Strong cryptography using the Sec ...
- phpstorm 2017.1 激活
打开网址 http://idea.lanyus.com/ 选择获取注册码,复制生成的验证码 安装完成后,打开软件,依次选择菜单栏 Help -> Register-> Activation ...
- Linux安装中文字体包
进入rhel5.5安装盘/Server路径找到字体安装包: fonts-chinese-3.02-12.el5.noarch.rpm fonts-ISO8859-2-75dpi-1.0-17.1.no ...
- java注解总结-关联信息-关联结构
java的注解是一种可配置信息: 这些信息直接依附在功能代码之上: * 元注解@Target,@Retention,@Documented,@Inherited * * @Target 表示该注解用于 ...
- 【洛谷4459】[BJOI2018] 双人猜数游戏(动态规划)
点此看题面 大致题意: 一直有两个数\(m,n\),已知\(s\le m\le n\),且\(Alice\)和\(Bob\)二个"最强大佬"各知道\(mn\)和\(m+n\).每轮 ...
- SpringMVC接受JSON参数详解
转:https://blog.csdn.net/LostSh/article/details/68923874 SpringMVC接受JSON参数详解及常见错误总结 最近一段时间不想使用Session ...
- war和war exploded的区别
是选择war还是war exploded 这里首先看一下他们两个的区别: (1)war模式这种可以称之为是发布模式,看名字也知道,这是先打成war包,再发布: (2)war exploded模式是直接 ...
- ES6初识-Decorator
开始先按照个插件 npm install babel-plugin-transform-decorators-lagacy --save-dev 1.扩充和修改类的行为 2.修改的行为@readonl ...
- MySQL的where条件优化
where 条件优化 适合select delete update 1.避免无用的括号 ((a AND b) AND c OR (((a AND b) AND (c AND d)))) -> ...