HDU Hangzhou Electric 1671/poj3630 Dictionary tree

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.