luogu#P9122. [USACO23FEB] Stamp Grid B
[USACO23FEB] Stamp Grid B
题目描述
A stamp painting is a black and white painting on an canvas, where certain cells are inked while others are blank. It can be described by an array of characters . The -th entry of the -th column of the array is equal to *
if the canvas contains ink at that square and .
otherwise.
Bessie has a stamp painting that she would like to create, so Farmer John has lent her a single stamp to do this and an empty canvas. Bessie can repeatedly rotate the stamp clockwise by and stamp anywhere on the grid as long as the stamp is entirely inside the grid. Formally, to stamp, Bessie chooses integers such that and ; for each such that , canvas cell is painted black if the stamp has ink at . Bessie can rotate the stamp at any time between stampings. Once a canvas cell is painted black, it remains black.
Farmer John is wondering whether it's possible for Bessie to create her desired stamp painting with his stamp. For each of test cases, help Farmer John answer this question.
输入格式
The first line of input contains , the number of test cases.
Each test case starts with an integer followed by lines, each containing a string of *
s and .
s, representing Bessie's desired stamp painting. The next line contains and is followed by lines, each containing a string of *
s and .
s, representing Farmer John's stamp.
Consecutive test cases are separated by newlines.
输出格式
For each test case, output YES
or NO
on separate lines.
题目大意
题目描述
盖章绘画是一幅黑白画,绘制在一个 的画布上,其中某些格子被涂黑,而其他格子为空白。它可以用一个 的字符数组表示()。如果数组的第 行第 列的值为 *
,说明该格子被涂黑;如果为 .
,则说明该格子为空白。
Bessie 想要完成一幅盖章绘画,因此 Farmer John 借给了她一块 ()的盖章,以及一块空的 画布。Bessie 可以将盖章顺时针旋转 ,并在画布上的任意位置盖章,只要盖章完全在画布范围内即可。形式化地说,盖章时,Bessie 选择整数 ,满足 且 ;对于每个 ,其中 ,画布上的格子 会被涂黑,如果盖章在 处有墨迹。Bessie 可以在每次盖章之前旋转盖章。一旦画布上的某个格子被涂黑,就会保持涂黑状态。
Farmer John 想知道,Bessie 是否可以用他的盖章完成她想要的盖章绘画。对于每个 ()个测试用例,帮助 Farmer John 回答这个问题。
输入格式
第一行包含一个整数 ,表示测试用例的数量。
每个测试用例以一个整数 开始,接下来是 行,每行包含由 *
和 .
构成的字符串,表示 Bessie 想要的盖章绘画。接下来的行包含一个整数 ,随后是 行,每行包含由 *
和 .
构成的字符串,表示 Farmer John 的盖章。
相邻的测试用例之间用空行分隔。
输出格式
对于每个测试用例,输出一行 YES
或 NO
。
样例 1 的解释
在第一个测试用例中,Bessie 可以按以下顺序完成盖章:
- 在 处盖章
- 在 处盖章
- 在 处盖章
在第二个测试用例中,Bessie 可以按以下顺序完成盖章:
- 在 处盖章
- 在 处盖章
- 顺时针旋转
- 顺时针旋转
- 在 处盖章
在第三个测试用例中,无法涂黑中间格子,因此无法完成绘画。
在第四个测试用例中,Bessie 可以按以下顺序完成盖章:
- 顺时针旋转
- 在 处盖章
- 在 处盖章
- 在 处盖章
4
2
**
*.
1
*
3
.**
.**
***
2
.*
**
3
...
.*.
...
3
.*.
...
...
3
**.
.**
..*
2
.*
*.
YES
YES
NO
YES
提示
Explanation for Sample 1
In the first test case, Bessie can perform the following sequence of stampings:
- Stamp at
- Stamp at
- Stamp at
In the second test case, Bessie can perform the following sequence of stampings:
- Stamp at
- Stamp at
- Rotate
- Rotate
- Stamp at
In the third test case, it is impossible to paint the middle cell.
In the fourth test case, Bessie can perform the following sequence of stampings:
- Rotate
- Stamp at
- Stamp at
- Stamp at