eolymp
bolt
Попробуйте наш новый интерфейс для отправки задач
Задачи

Where`s Wally

Where`s Wally

Do you know the famous series of children’s books named "Where’s Wally"? Each of the books contains a variety of pictures of hundreds of people. Readers are challenged to find a person called Wally in the crowd. We can consider "Where’s Wally" as a kind of pattern matching of two-dimensional graphical images. Wally’s figure is to be looked for in the picture. It would be interesting to write a computer program to solve "Where’s Wally", but this is not an easy task since Wally in the pictures may be slightly different in his appearances. We give up the idea, and make the problem much easier to solve. You are requested to solve an easier version of the graphical pattern matching problem. An image and a pattern are given. Both are rectangular matrices of bits (in fact, the pattern is always square-shaped). \textbf{0} means white, and \textbf{1} black. The problem here is to count the number of occurrences of the pattern in the image, i.e. the number of squares in the image exactly matching the pattern. Patterns appearing rotated by any multiples of \textbf{90} degrees and/or turned over forming a mirror image should also be taken into account. \InputFile The input is a sequence of datasets each in the following format. \textbf{w h p image data pattern data} The first line of a dataset consists of three positive integers \textbf{w}, \textbf{h} and \textbf{p}. \textbf{w} is the width of the image and \textbf{h} is the height of the image. Both are counted in numbers of bits. \textbf{p} is the width and height of the pattern. The pattern is always square-shaped. You may assume \textbf{1} ≤ \textbf{w} ≤ \textbf{1000}, \textbf{1} ≤ \textbf{h} ≤ \textbf{1000}, and \textbf{1} ≤ \textbf{p} ≤ \textbf{100}. The following \textbf{h} lines give the image. Each line consists of \textbf{w/6} (which is equal to \textbf{(w+5)/6}) characters, and corresponds to a horizontal line of the image. Each of these characters represents six bits on the image line, from left to right, in a variant of the \textbf{BASE64} encoding format. The encoding rule is given in the following table. The most significant bit of the value in the table corresponds to the leftmost bit in the image. The last character may also represent a few bits beyond the width of the image; these bits should be ignored. The last \textbf{p} lines give the pattern. Each line consists of \textbf{p/6} characters, and is encoded in the same way as the image. A line containing three zeros indicates the end of the input. The total size of the input does notexceed two megabytes. \OutputFile For each dataset in the input, one line containing the number of matched squares in the image should be output. An output line should not contain extra characters. Two or more matching squares may be mutually overlapping. In such a case, they are counted separately. On the other hand, a single square is never counted twice or more, even if it matches both the original pattern and its rotation, for example.
Лимит времени 10 секунд
Лимит использования памяти 32 MiB
Входные данные #1
48 3 3
gAY4I4wA
gIIgIIgg
w4IAYAg4
g
g
w
153 3 3
kkkkkkkkkkkkkkkkkkkkkkkkkg
SSSSSSSSSSSSSSSSSSSSSSSSSQ
JJJJJJJJJJJJJJJJJJJJJJJJJI
g
Q
I
1 1 2
A
A
A
384 3 2
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/
BCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/A
CDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/AB
A
A
0 0 0
Выходные данные #1
8
51
0
98
Источник ACM ICPC Regionals 2010, Asia, Tokyo