HDU 2222 Keywords Search (blind)

Source: Internet
Author: User

Keywords Search

Time limit:2000/1000 MS (java/others) Memory limit:131072/131072 K (java/others)
Total submission (s): 50451 Accepted Submission (s): 16236


Problem DescriptionIn The modern time, Search engine came into the life of everybody like Google, Baidu, etc.
Wiskey also wants to bring the feature to his image retrieval system.
Every image has a long description, when users type some keywords to find the image, the system would match the keywords W ITH description of image and show the image which the most keywords be matched.
To simplify the problem, giving you a description of image, and some keywords, you should tell me how many keywords would b E match.

Inputfirst line would contain one integer means how many cases would follow by.
Each case would contain integers n means the number of keywords and n keywords follow. (N <= 10000)
Each keyword would only contains characters ' a '-' Z ', and the length would be is not longer than 50.
The last line is the description, and the length would be a not longer than 1000000.

Outputprint How many keywords is contained in the description.

Sample INPUT15SHEHESAYSHRHERYASHERHS

Sample OUTPUT3

Authorwiskey

/************************************************author:guanjuncreated time:2016/5/26 22:17:48File Name: 2222.cpp*************************************************/#include<iostream>#include<cstring>#include<cstdlib>#include<stdio.h>#include<algorithm>#include<vector>#include<queue>#include<Set>#include<map>#include<string>#include<math.h>#include<stdlib.h>#include<iomanip>#include<list>#include<deque>#include<stack>#defineull unsigned long Long#definell Long Ling#defineMoD 90001#defineINF 0x3f3f3f3f#defineMAXN 250010#defineCLE (a) memset (A,0,sizeof (a))Constull inf = 1LL << A;Const Doubleeps=1e-5;using namespacestd;structacauto{intch[maxn][ -]; intsz; intF[MAXN],LAST[MAXN],VAL[MAXN],CNT[MAXN]; voidinit () {sz=1; memset (ch[0],0,sizeofch[0]); memset (CNT,0,sizeofCNT); }    intIdxCharc) {        returnC-'a'; }    voidAddChar*s,intv) {        intu=0, len=strlen (s);  for(intI=0; i<len;i++){            intC=idx (s[i]); if(!Ch[u][c]) {memset (Ch[sz],0,sizeofCh[sz]); VAL[SZ]=0; CH[U][C]=sz++; } u=Ch[u][c]; } Val[u]=v; }    voidGetfail () {Queue<int>Q; f[0]=0;  for(intC=0;c< -; C + +){            intu=ch[0][c]; if(U) {F[u]=0;                Q.push (U); Last[u]=0; }        }         while(!Q.empty ()) {            intR=Q.front (); Q.pop ();  for(intC=0;c< -; C + +){                intu=Ch[r][c]; if(!u) {Ch[r][c]=Ch[f[r]][c]; Continue;                } q.push (U); F[u]=Ch[f[r]][c]; Last[u]=val[f[u]]?F[u]:last[f[u]]; }        }    }    voidPrintintj) {        if(j) {Cnt[val[j]]++;        Print (Last[j]); }    }    voidFind (Char*T) {        intn=strlen (T); intj=0;  for(intI=0; i<n;i++){            intC=idx (t[i]);  while(J&&!ch[j][c]) j=F[j]; J=Ch[j][c]; if(Val[j]) print (j); Else if(Last[j]) print (last[j]); }}}ac;Chars[10010][ -],t[1000010];intBkdrhash (Char*s) {    Long LongSeed=131; Long LongHash=0;  while(*s=='0') s++;  while(*s) {hash=hash*seed+ (*s++); }    return(Hash &0x7FFFFFFF);} Map<int,int>MP;intMain () {#ifndef Online_judge freopen ("In.txt","R", stdin); #endif    //freopen ("OUT.txt", "w", stdout);    intT,n; CIN>>T;  while(t--) {ac.init ();        Mp.clear (); scanf ("%d",&N);  for(intI=1; i<=n;i++) {scanf ("%s", S[i]);            Ac.add (S[i],i); intx=Bkdrhash (S[i]); MP[X]++;        } ac.getfail (); scanf ("%s", T); Ac.        Find (T); intans=0;  for(intI=1; i<=n;i++){            intx=Ac.cnt[i]; inty=Bkdrhash (S[i]); if(x>0) {ans+=Mp[y]; }} printf ("%d\n", ans); }    return 0;}

HDU 2222 Keywords Search (blind)

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.