Transmission Door
Test Instructions: Enter n string number to find out if there is a string with the same prefix if there is output no otherwise output Yes
Ideas: Use the dictionary tree to resolve the end of the tag dictionary tree to find out if there is a node inside a string if there is a string that indicates the same prefix
When inserting a dictionary tree, determine if there is a
AC Code:
1#include"iostream"2#include"stdio.h"3#include"string.h"4 using namespacestd;5 6 using namespacestd;7typedefLong Longll;8 #defineMem (a) memset (A,0,sizeof (a))9 TentypedefstructTrie One { A BOOLIsword; - structTrie *next[Ten]; -}*Trie_pointer; the -Trie trie[300005]; - - intTot,flag; + - trie_pointer CreateNode () + { A return&trie[tot++]; at } - - voidInsert (Trie_pointer root,Char*s) - { - if(*s = =' /') - return; in Char*p =s; -Trie_pointer tmp,t =Root; to while(*p! =' /') + { - if(T->next[*p-'0'] ==NULL) the { *TMP =CreateNode (); $T->next[*p-'0'] =tmp;Panax Notoginseng } -t = t->next[*p-'0']; thep++; + if(T->isword = =1) AFlag =1; the } +T->isword =1; - for(intI=0; i<Ten; i++) $ { $ if(T->next[i]! =NULL) -Flag =1; - } the } - Wuyi intMain () the { - Trie Root; Wu Chars[2005]; - inti,n,t; AboutCin>>T; $ while(t--) - { -memset (Trie,0,sizeof(Trie)); -memset (&root,0,sizeof(root)); Atot=0; +Cin>>N; the while(n--) - { $Cin>>s; the if(!flag) theInsert (&root,s); the } the if(flag) -printf"no\n"); in Else theprintf"yes\n"); theFlag =0; About } the return 0; the}
HDU Hangzhou Electric 1671/poj3630 Dictionary tree