Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=2087
Cut the flower cloth
Time limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 11544 Accepted Submission (s): 7421
Problem description A piece of flower cloth, there are some patterns, there is a directly available small bar, there are some patterns. For a given strip of flowers and strips, calculate how many pieces of strips can be cut from the flower cloth?
Input inputs contain some data, respectively, is a pair of flowers and small strips, the cloth is shown with visible ASCII characters, the number of visible ASCII characters, the pattern of the cloth is also how many kinds of patterns. The strips and strips are not more than 1000 characters in length. If you meet the # character, you are no longer working.
Output outputs can be cut from the pattern cloth up to the number of small strips, if not a piece, then honestly output 0, each result should be wrapped.
Sample INPUTABCDE a3aaaaaa aa#
Sample Output03
Data good water, KMP sample but the problem directly
1#include <cstdio>2#include <cstdlib>3#include <cstring>4#include <algorithm>5#include <iostream>6#include <cmath>7#include <queue>8#include <map>9#include <stack>Ten#include <list> One#include <vector> A - using namespacestd; - the Const intMAXN =1010; - intna, NB; - CharA[MAXN]; - CharB[MAXN]; + intPRE[MAXN]; - + //B is the pattern string, a is the target string A voidGetpre (Char*b,int*pre) { at intJ, K; -pre[0] = -1; -j =0; -K =-1; - while(J <nb) { - if(k = =-1|| B[J] = =B[k]) { inJ + +; -k++; toPRE[J] =K; + } - Else { theK =Pre[k]; * } $ }Panax Notoginseng } - the intKMP () { + intAns =0; A inti =0; the intj =0; + Getpre (b, pre); - while(I <na) { $ if(j = =-1|| A[i] = =B[j]) { $i++; -J + +; - } the Else { -j =Pre[j];Wuyi } the if(J = =nb) { -ans++; Wu } - if(i = =na) { About returnans; $ } - } - } - A intMain () { + //freopen ("in", "R", stdin); the while(SCANF ("%s", a) && strcmp (A,"#") !=0) { -scanf"%s", b); $Na =strlen (a); theNB =strlen (b); the Getpre (b, pre); theprintf"%d\n", KMP ()); the } -}
[HDOJ2087] cut the flower cloth