1, HDU 1251 statistical puzzles trie Tree template problem, or map
2, Summary: with C + +, g++ on the burst of memory.
Test instructions: Finds the number of words for a given prefix.
#include <iostream>#include<cstring>#include<cmath>#include<queue>#include<algorithm>#include<cstdio>#defineMax (A, b) a>b?a:b#defineF (I,A,B) for (int i=a;i<=b;i++)#defineMes (A, b) memset (A,b,sizeof (a))#defineINF 0x3f3f3f3f#defineLL Long Longusing namespacestd;Const intn=10010, max=1000100;structnode{intcount; Node*child[ -]; Node () {mes (child,null); Count=0; }}; Node*root=Newnode,*Current ;voidInsertChar*str) { Current=Root; for(intI=0; str[i];++i) { intm=str[i]-'a'; if(current->child[m]==NULL) { Current->child[m]=NewNode; } Current=current->Child[m]; Current->count++; }}intSearchChar*str) { Current=Root; for(intI=0; str[i];++i) { intm=str[i]-'a'; if(current->child[m]==NULL)return 0; Current=current->Child[m]; } returnCurrent->count;}intMain () {Charstr[ -]; while(Gets (str), *str) insert (str); while(gets (str)) printf ("%d\n", Search (str)); return 0;}
View Code
HDU 1251 Trie Tree Template title