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 & ...
随机推荐
- yum第三方源
EPEL RHEL 6: http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm RHEL 7: http:// ...
- Selenium入门13 cookie的增删改查
cookie的增删改查: 查询:get_cookies()查询所有cookie,get_cookie(cookie的name)获取单个cookie 删除:delete_cookie(cookie的na ...
- MMU CPU及思想
要素: 1)CPU访问寻址地址空间: 2)内存不足以容纳所有进程数据: 3)MMU将进程数据分割,保留当前使用数据. http://baike.baidu.com/link?url=KHyp37Ysi ...
- 2019.03.15 ZJOI2019模拟赛 解题报告
得分: \(20+45+15=80\)(三题暴力全写挂...) \(T1\):Lyk Love painting 首先,不难想到二分答案然后\(DP\)验证. 设当前需验证的答案为\(x\),则一个暴 ...
- 2017.9.27 JavaWeb 属性的设置和获取
3.4.3新属性的设置和获取 对于getpParamter方法是通过参数传递获得数据, 设置数据的方法格式: void request.setAttribute("key",Ob ...
- mysql数值函数
abs(x) -- 绝对值 abs(-10.9) = 10 format(x, d) -- 格式化千分位数值 format(1234567.456, 2) = 1,234,567.46 ceil(x) ...
- caffe的损失函数
损失函数,一般由两项组成,一项是loss term,另外一项是regularization term. J=L+R 先说损失项loss,再说regularization项. 1. 分对得分1,分错得分 ...
- JQuery基础原理 与实例 验证表单 省市联动 文本框判空 单选 复选 判空 下拉判空 确认密码判等
JQuery 基础原理 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> & ...
- mysql数据库设置外键,更新与删除选项
CASCADE:父表delete.update的时候,子表会delete.update掉关联记录:SET NULL:父表delete.update的时候,子表会将关联记录的外键字段所在列设为null, ...
- MySQL的where条件优化
where 条件优化 适合select delete update 1.避免无用的括号 ((a AND b) AND c OR (((a AND b) AND (c AND d)))) -> ...