1622: [Usaco2008 Open]word Power name Energy time limit:5 Sec Memory limit:64 MB
submit:370 solved:184
[Submit] [Status] [Discuss] Description John wanted to calculate the energy of his N (1≤n≤1000) cow's name. Each cow's name is made up of no more than 1000 characters, and no name is an empty string, and John has an "energy strings table" with a string of M (1≤m≤100) representing energy. Each string consists of no more than 30 fonts, and there is no empty string. How many energy strings a cow's name contains, and how much energy this name has. The so-called "implication" means that all the characters of an energy string appear sequentially (not necessarily one after the other) in the name string. All uppercase and lowercase letters are equivalent. For example, in Bessie's name "Bessie", there are strings such as "be", "SI", "EE" and "Es", but not "LS" or "EB". Please help John calculate the energy of his cow's name. Input line 1th enters two integers n and m, then each row of n lines enters a cow's name, followed by an energy string for each row of m rows. Output is a total of n rows, an integer per line, followed by the energy of a name. Sample Input5 3
Bessie
Jonathan
Montgomery
Alicia
Angola
Se
Ngo
Ont
INPUT DETAILS:
There is 5 cows, and their names is "Bessie", "Jonathan",
"Montgomery", "Alicia", and "Angola". The 3 good strings is "se",
"NGo", and "Ont".
Sample Output1
1
2
0
1
OUTPUT DETAILS:
"Bessie" contains "se", "Jonathan" contains "Ont", "Montgomery" contains
Both "NGo" and "Ont", Alicia contains none of the good strings, and
"Angola" contains "NGo".
HINT Source
Silver
The problem: This question obviously can be violent casually thank water, but if such a word is far from spicy fun, so I once again invited out the line of Meng Meng Tree--
The segment tree stores each name, and then even maintenance is not necessary, directly implemented to find in a certain interval range of the most left of a specified letter position, and then with this, you can directly use the following substring to match the front name, Complexity O (NMLLOGM) (incredibly or 2988 Ms Water passed, Good fun)
1/**************************************************************2Problem:16223 User:hansbug4 language:pascal5 result:accepted6Time:2988Ms7Memory:2448KB8****************************************************************/9 Ten var One I,j,k,l,m,n,ans:longint; A ss:ansistring; -B,c:Array[0..10000] ofansistring; -A:Array[0..10000,0.. -] ofLongint; the functionmin (x,y:longint): Longint;inline; - begin - ifX<y ThenMin:=xElsemin:=y; - End; + functionMax (x,y:longint): Longint;inline; - begin + ifX>y ThenMax:=xElsemax:=y; A End; at procedurebuilt (z,x,y:longint); - varI:longint; - begin - if(x=y) Then -A[z,ord (Ss[x])- -]:=1 - Else in begin -Built (z*2, X, (X+y)Div 2); toBuilt (z*2+1, (X+y)Div 2+1, y); + fori:=1 to - Doa[z,i]:=a[z*2, i]+a[z*2+1, I] - End; the End; * functionapproach (z,x,y,l,r,t:longint): Longint; $ varA1:longint;Panax Notoginseng begin - ifL>r ThenExit0); the ifa[z,t]=0 ThenExit0); + ifX=y Thenexit (x); AA1:=approach (z*2, X, (X+y)Div 2, L,min (R, (x+y)Div 2), t); the ifA1<>0 Thenexit (A1); +Exit (Approach (z*2+1, (X+y)Div 2+1, Y,max (L, (x+y)Div 2+1) , r,t)); - End; $ $ - begin - readln (n,m); the fori:=1 toN Do - beginWuyi readln (B[i]); theb[i]:=upcase (B[i]); - End; Wu fori:=1 toM Do - begin About readln (C[i]); $c[i]:=upcase (C[i]); - End; - fori:=1 toN Do - begin Ass:=B[i]; +Fillchar (A,sizeof (a),0); theBuilt1,1, Length (ss)); -ans:=0; $ forj:=1 toM Do the begin thel:=0; the fork:=1 toLength (C[j]) Do the begin -L:=approach (1,1, Length (ss), L +1, Length (ss), Ord (C[j][k])- -); in ifL=0 ThenBreak ; the End; the ifL<>0 ThenInc (ANS); About End; the writeln (ans); the End; the End.
1622: [Usaco2008 Open]word Power name Energy