HDU 3695 computer Virus on Planet Pandora (AC self-starter)

Source: Internet
Author: User



Test instructions: There are n kinds of virus sequences (strings), a pattern string that asks this string to include several viruses.


Including the opposite virus is counted. The string [QX] indicates that there is a Q x character. See the case in detail.


0 < Q <= 5,000,000 altogether not super, no solution

32abdcbdacb3abccdeghiabccdefihg4abbacdeebbbfeeea[2b]cd[4e]f

Sample Output
032Hintin the "second case" in the sample input, the reverse of the program was ' GHIFEDCCBA ', and ' GHI ' is a Substri Ng of the reverse, so the program was infected by virus ' GHI '.


#include <stdio.h> #include <string.h> #include <stdlib.h> #include <string> #include <queue > #include <math.h> #include <algorithm> #include <iostream>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;//failed pointer 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&AMP;&AMP;TEMP-&GT;COUNT!=-1)//along the mismatch side walk, walked not walk {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<l;)              {if (str1[i]!= ' [') str[j++]=str1[i++];  else {/*for (k=i+1;str1[k]!= '] '; k++);  int v=0,w=1;for (int l=k-2;l>=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]= ' + ';            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*/


HDU 3695 computer Virus on Planet Pandora (AC self-starter)

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.