Stamp painting is a black and white painting on an N by N canvas, in which some cells are inked and others are blank. It can be described as an N by N character array(1≤N≤20). If the canvas contains ink at the square and, the i-th entry in the JTH column of the array is equal to *. Otherwise
Bessie had a stamp painting she wanted to create, so Farmer John lent her a K×K(1≤K≤N) stamp and an empty N×N canvas. Bessie can seal clockwise 90 ∘, and in any position on the grid and sealed, as long as the seal completely within the grid. Formally, for seal, Bessie selects the integers i, j, such that i∈[1, N−K+1] and j∈[1, N−K+1]; For each(i ', j '), such that 1≤i ', j '≤K, canvas cells(i+i' −1, j+j '−1) are painted black if the stamp has ink at(i', j '). Bessie can rotate the stamp at any time between stamping. Once the canvas cell is painted black, it will remain black.
Farmer John wanted to know if it would be possible for Bessie to use his stamps to create the stamps she wanted. For each T(1≤T≤100) test case, help Farmer John answer this question.INPUT FORMAT(input from terminal /stdin) :
The first line of input contains T, the number of test cases.
Each test case begins with an integer N followed by N lines, each containing a s and.s string to represent the stamp drawing required for Bessie. The next line contains K, followed by K lines, each containing a and.s string, representing Farmer John's stamp.
Successive test cases are separated by newlines.
OUTPUT FORMAT(to print the output to terminal/standard output) :
Output "YES" or "NO" on a separate line for each test case.
Sample input:
4.
2.
**
*.
1.
*
3.
.**
.**
2.
.*
**
3.
...
.*.
...
3.
.*.
...
...
3.
**.
.**
.. *
2.
.*
*.
Sample output:
YES
YES
NO
YES
In the first test case, Bessie can perform the following stamping sequence:
Stamp at(1,1)
Stamp at(1,2)
Stamp(2,1)
In the second test case, Bessie can perform the following stamping sequence:
Stamp(2,2)
Stamp(2,1)
Rotates 90 ∘Rotates 90 ∘
Stamp at(1,2)
In the third test case, it is not possible to draw an intermediate cell.
In the fourth test case, Bessie can perform the following stamping sequence:
Rotates 90 ∘
Stamp at(1,1)
Stamp at(1,2)
Stamp(2,2)
This is the topic assigned by the school today, I do not know, I hope you can help to solve it(using C++ algorithm), most hope to give the code and ideas!
0 Answer
No answer yet
这家伙很懒,什么都没留下...