hdu 1251 统计难题 (字典树入门题)
/*******************************************************
题目: 统计难题 (hdu 1251)
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1251
算法: 字典树
提示: 这题压要用c++提交,G++会超内存
*******************************************************/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
char s[];
typedef struct Node
{
Node *next[];
int cut;
}Node;
Node *root;
void inser(char *s)
{
Node *p=root;
for (int i=;s[i];i++)
{
int x=s[i]-'a';
if (p->next[x]==NULL)
{
p->next[x]=(Node *)malloc(sizeof(Node));
p->next[x]->cut=;
for (int i=;i<;i++) p->next[x]->next[i]=NULL;
}
p=p->next[x];
p->cut++;
}
}
int Find(char *s)
{
Node *p=root;
for (int i=;s[i];i++)
{
int x=s[i]-'a';
if (p->next[x]==NULL) return ;
p=p->next[x];
}
return p->cut;
}
int main()
{
root=new Node();
while (gets(s))
{
if (strcmp(s,"")==) break;
else inser(s);
}
while (gets(s))
{
printf("%d\n",Find(s));
}
return ;
}
hdu 1251 统计难题 (字典树入门题)的更多相关文章
- hdu 1251 统计难题 字典树第一题。
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submi ...
- HDU 1251 统计难题 字典树大水题
今天刚看的字典树, 就RE了一发, 字典树原理还是很简单的, 唯一的问题就是不知道一维够不够用, 就开的贼大, 这真的是容易MLE的东西啊, 赶紧去学优化吧. HDU-1251 统计难题 这道题唯一的 ...
- hdu -1251 统计难题(字典树水题)
http://acm.hdu.edu.cn/showproblem.php?pid=1251 建树之后 查询即可. G++提交 ME不知道为什么,c++就对了. #include <iostre ...
- HDOJ/HDU 1251 统计难题(字典树啥的~Map水过)
Problem Description Ignatius最近遇到一个难题,老师交给他很多单词(只有小写字母组成,不会有重复的单词出现),现在老师要他统计出以某个字符串为前缀的单词数量(单词本身也是自己 ...
- hdu 1251 统计难题(字典树)
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others) Total Subm ...
- hdu 1251 统计难题 (字典树(Trie)<PS:C++提交不得爆内存>)
统计难题Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submis ...
- HDU 1251 统计难题(字典树)
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submi ...
- HDU 1251统计难题 字典树
字典树的应用. 数据结构第一次课的作业竟然就需要用到树了!!!这不科学啊.赶紧来熟悉一下字典树. 空间开销太大T T #include<cstdio> #include<cstrin ...
- hdu 1251 统计难题(trie树入门)
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submi ...
随机推荐
- webstrom11 和12破解码
很多人都发现 http://idea.lanyus.com/ 不能激活了 很多帖子说的 http://15.idea.lanyus.com/ 之类都用不了了,最近封的厉害仅作测试. 红色字体的是最近大 ...
- Excel 取得一定范围内最大的有值的行号
dim iRow iRow = Range("A1000").End(xlUp).Row
- javascript call与apply关键字的作用
apply接受两个参数.第一个参数指定函数体内this对象的指向,第二个参数为一个带下标的集合. call则是apply的语法糖,如果参数数量固定,则可以不用带下标的集合传第二个参数. 1 2 3 4 ...
- 通过java反射,封装bean
上周有一个封装javabean的流程,成员变量有好多,一路写if(!=null){setXXX} 真的好麻烦,有时候一不小心还会漏掉,很是麻烦,就想到用反射的方法自动进行拼装bean. bean pa ...
- Linux:下载方式安装lrzsz
若机器服务使用yum源安装,可先下载好lrzsz文件后再上传安装 步骤一: 先下载lrzsz的tar包:wget https://ohse.de/uwe/releases/lrzsz-0.12.20. ...
- LeetCode-179. Largest Number
179. Largest Number Given a list of non negative integers, arrange them such that they form the larg ...
- UITableViewCell重用导致内容混乱方案
UITableViewCell *cell=nil; static NSString *reuse=@"cell"; if (cell==nil) { cell=[[UITable ...
- java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.FutureTask@1f303192 rejected from java.util.concurrent.ThreadPoolExecutor@11f7cc04[Terminated, pool size = 0, active threads
java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.FutureTask@1f303192 rejec ...
- PriorityQueue优先队列用法入门
PriorityQueue是队列的一种,它叫做优先队列,该类实现了Queue接口. 之所以叫做优先队列,是因为PriorityQueue实现了Comparator这个比较接口,也就是PriorityQ ...
- Python:关于字典的相关操作
>>> people = {"Tom":170, "Jack":175, "Kite":160, "White& ...