HDU 3695 Computer Virus on Planet Pandora (AC automatic machine)

Source: Internet
Author: User



Question: There are n Virus sequences (strings), a pattern string that contains several viruses.


If the string contains the opposite virus, [qx] indicates that the string contains q x characters. For details, see the case column.


0 <q <= 5,000,000.

32ABDCBDACB3ABCCDEGHIABCCDEFIHG4ABBACDEEBBBFEEEA[2B]CD[4E]F

Sample Output
032HintIn the second case in the sample input, the reverse of the program is ‘GHIFEDCCBA’, and ‘GHI’ is a substring of the reverse, so the program is infected by virus ‘GHI’.


# Include
 
  
# Include
  
   
# Include
   
    
# Include
    
     
# Include
     
      
# Include
      
        # Include
       
         Using namespace std; const int kind = 26; const int maxn = 250*1000; // Note RE, word length * Number of words const int M = 5100000; struct node {node * fail; node * next [kind]; int count; node () {fail = NULL; count = 0; memset (next, 0, sizeof (next) ;}} * q [maxn]; char keyword [1010], str [M], str1 [M]; int head, tail; void insert (char * str, node * root) {node * p = root; int I = 0, index; while (str [I]) {index = str [I]-'A'; if (p-> next [index] = NULL) p-> next [index] = new node (); p = p-> next [index]; I ++;} p-> count ++ ;} void build_ac (node * root) {int I; root-> fail = NULL; q [head ++] = root; while (head! = Tail) {node * temp = q [tail ++]; node * p = NULL; for (I = 0; I <26; I ++) {if (temp-> next [I]! = NULL) {if (temp = root) temp-> next [I]-> fail = root; // The failure Pointer Points to root else {p = temp-> fail; while (p! = NULL) {if (p-> next [I]! = NULL) {temp-> next [I]-> fail = p-> next [I]; break;} p = p-> fail ;} if (p = NULL) temp-> next [I]-> fail = root;} q [head ++] = temp-> next [I] ;}} int query (node * root) {int I = 0, cnt = 0, index, len = strlen (str); node * p = root; while (str [I]) {index = str [I]-'A'; while (p-> next [index] = NULL & p! = Root) p = p-> fail; p = p-> next [index]; p = (p = NULL )? Root: p; node * temp = p; while (temp! = Root & temp-> count! =-1) // the path along the mismatched side does not go through {cnt + = temp-> count; temp-> count =-1; temp = temp-> fail ;} I ++;} return cnt;} int value (int p, int q) {int I, ans = 0, w = 1; for (I = q; i> = p; I --) {ans + = (str1 [I]-'0') * w; w * = 10;} return ans;} int main () {int n, t; scanf ("% d", & t); while (t --) {head = tail = 0; node * root = new node (); scanf ("% d", & n); while (n --) {scanf ("% s", keyword); insert (keyword, root);} build_ac (root ); scanf ("% s", str1); int l = strlen (str1), I, j, k; j = 0; for (I = 0; I
        
          = I + 1; l --) {v + = (str1 [l]-'0') * w; w * = 10;} */int v = 0; I ++; while (str1 [I]> = '0' & str1 [I] <= '9 ') {v = v * 10 + str1 [I]-'0'; I ++;} for (int k1 = 1; k1 <= v; k1 ++) str [j ++] = str1 [I]; I + = 2 ;}} str [j] = '\ 0'; // printf ("% s \ n ", str); int h = query (root); char chh; l = strlen (str); for (I = 0; I <= L-1)/2; I ++) {chh = str [l-i-1]; str [l-i-1] = str [I]; str [I] = chh;} // printf ("% s", str ); h + = query (root); printf ("% d \ n", h);} return 0;}/* 32ABDCBDACB3ABCCDEGHIABCCDEFIHG4ABBACDEEBBBFEEEA [2B] CD [4E] F */
        
       
      
     
    
   
  
 


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.