http://acm.hdu.edu.cn/showproblem.php?pid=1075 ;}…
;} 之前写的#include<iostream> #include<algorithm> #include<stdio.h> using namespace std; struct node { int sum; node]; }; void buildtrietree(node *head, char s[]) { node *p=new node(); p=head; for; s[i]; i++) { int k=s[i]-'a'; if) p->next…
对于字典树和01字典树的一点理解: 首先,字典树建树的过程就是按照每个数的前缀来的,如果你要存储一个全小写字母字符串,那么这个树每一个节点最多26个节点,这样的话,如果要找特定的单词的话,按照建树的方式找就可以了. 然后是01字典树,这个树在处理一些异或问题的时候特别好用,首先在存储一个树的过程中,我们是按照从高位开始的,如果是对于int型的,我们就从这个数的32位开始存储,不够的话,按照0补,这是建树的过程.再就是查询的时候,对于给定的数,我们先去找这一位上和他不同的,比如说,如果当前这个数的…
What Are You Talking About Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 102400/204800 K (Java/Others)Total Submission(s): 12617    Accepted Submission(s): 4031 Problem Description Ignatius is so lucky that he met a Martian yesterday. But…
刚学的字典树,代码写得很不熟练.写法上也没有什么特别的优化,就是以1A为第一目标! 可惜还是失败了. 少考虑了一种情况,就是一个单词是另一个单词前缀的问题,写了好久,还是没有1A.不过感觉对字典树有了更深刻的理解. 代码写得不好,看看别人都是怎么写字典树的去. #include<stdio.h> #include<string.h> #include<malloc.h> struct node { node *a[27]; char s[15]; }; char s1[…
What Are You Talking About Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 102400/204800 K (Java/Others)Total Submission(s): 21658    Accepted Submission(s): 7228 Problem Description Ignatius is so lucky that he met a Martian yesterday. But…
/******************************************************* 题目: 统计难题 (hdu 1251) 链接: http://acm.hdu.edu.cn/showproblem.php?pid=1251 算法: 字典树 提示: 这题压要用c++提交,G++会超内存 *******************************************************/ #include<cstdio> #include<cstr…
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5687 2016百度之星资格赛C题,直接套用字典树,顺便巩固了一下自己对字典树的理解 #include<stdio.h> #include<string.h> struct node{ ]; int cnt; void init(){ cnt = ;//计数 memset(next,-,sizeof(next)); } }; ]; ;//记录节点数 void insert(char *s){…
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5384 用字典树.AC自动机两种做法都可以做 #include<stdio.h> #include<string.h> #include<string> #include<iostream> using namespace std; struct node{ int cnt; node *next[]; node(){ cnt = ; ;i<;i++) next…
统计难题 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131070/65535 K (Java/Others)Total Submission(s): 16905    Accepted Submission(s): 7273 Problem Description Ignatius最近遇到一个难题,老师交给他很多单词(只有小写字母组成,不会有重复的单词出现),现在老师要他统计出以某个字符串为前缀的单词数量(单词本身也是自己的前…