随笔分类 -  数据结构—trie树

Colored Sticks(彩色棒)
摘要:poj 2513题目大意:给一些彩色棒,看能不能组成一个解决:trie+无向图欧拉路(偶数结点度数为0或者2)clude <iostream> #include <cstring>#include <cstdio>using namespace std;struct node{ int next[26]; int wordNo;};int top;int num;node tree[2000000];short adj[510010];int data[510010];void init(){ top=1; num=0; memset(data,-1,si. 阅读全文
posted @ 2011-08-31 20:52 猿类的进化史 阅读(386) 评论(0) 推荐(0)
Keywords Search(查找关键字)
摘要:hdoj 2222题目大意:给出一些字符串 ,再给出一段文字,问文字中出现多少个单词解决:AC自动机#include <iostream>#include <cstring>#include <queue>#include <cstdio>using namespace std;#define s scanfint top;struct node{ int cnt; int fail; int next[26];};node tree[400000];char mai[1000005];void init(){ top=1; memset(tre 阅读全文
posted @ 2011-08-30 21:55 猿类的进化史 阅读(632) 评论(0) 推荐(0)
统计难题
摘要:hdoj1251题目大意: 求出以某字符串为前缀的单词的数量解决:trie树#include <iostream>#include <cstring>using namespace std;struct node{ int cnt; int next[26];};node trie[3000000];int top=0;void init(){//初始化字典树,0号为根节点,只需将next值置为0就行了 memset(trie[0].next,0,sizeof(trie[0].next)); top=1;}void insert(char *str){ int i=0, 阅读全文
posted @ 2011-08-10 17:29 猿类的进化史 阅读(288) 评论(0) 推荐(0)
phone list(电话簿)
摘要:poj3630题目大意:给若干字符串,判断是否是前缀解决:trie树的应用,由于字符串的长度不一插入是要注意#include <iostream>#include <cstdio>#include <string>#include <cstring>using namespace std;struct node{ bool isword; int next[10];};node tree[100000];int top;bool flag;void init(){ tree[0].isword=false; memset(tree[0].next 阅读全文
posted @ 2011-08-08 10:26 猿类的进化史