#P6972. [NEERC2016] Kids Designing Kids

[NEERC2016] Kids Designing Kids

题目描述

Kevin and Kimberly have freckles on their foreheads.

They both drew their freckle pictures on sheets of paper. Each picture is a rectangle of pixels: every cell either has a freckle or it has no freckle.

They are jokingly proposing that when they grow up, marry, and have a child, her freckle picture is produced as a result of the following procedure:

Kevin's and Kimberly's pictures are moved by a parallel translation, and then in each cell a child has a freckle if and only if exactly one of the parents has a freckle in this position.

Now they wonder, whether there is a parallel translation that gives their child a specific freckle picture (for example, a lightning), and what is this parallel translation.

输入格式

The first line contains two integers, h1andw1(1h1,w11000)h_{1 }and w_{1} (1 \le h_{1}, w_{1} \le 1000) -- the height and the width of Kevin's freckle picture. Each of the next h1h_{1} lines consists of w1w_{1} characters ב \times ' and ..‘. '. Character ב \times ' means that there is a freckle, and .‘. ' that there is not.

The next lines contain Kimberly's picture in the same format. Its height and width h2h_2 and w2w_2 follow the same constraints.

It is guaranteed that Kevin and Kimberly have at least one freckle each.

The next lines contain the picture they want for their child in the same format. Its dimensions h3h_{3} and w3w_{3} also have the same constraints.

输出格式

In the first line output YES if the desired picture can be produced, and NO otherwise.

If the answer is positive, then in the second line output two integers, xx and yy , with the following meaning: if you overlay the pictures so that their upper left corners coincide, then move Kimberly's picture xx cells right (negative number means moving picture left) and yy cells down (negative number means moving picture up), and then apply the procedure described above, the resulting picture can be moved by a parallel translation to coincide with the third picture from the input file.

题目大意

给定三个 01 矩阵(* 表示 11. 表示 00),大小分别为 h1×w1h_1\times w_1h2×w2h_2\times w_2h3×w3h_3\times w_3,你可以将前两个矩阵的左上角重叠,然后将第二个矩阵向右平移 xx 个长度、向下平移 yy 个长度(x,yx,y 可以为负数,表示反方向)。然后将对应位置异或起来(超出部分均视为 00)。

你需要判断得到的矩阵是否可能能够通过平移和第三个矩阵重合(超出部分均视为 00),并给出方案。

保证前两个矩阵都含有至少一个 11

h,w103h,w\le 10^3

3 3
..*
.*.
*.*
3 3
**.
..*
.*.
5 2
.*
*.
**
.*
*.

YES
0 2

提示

Time limit: 2 s, Memory limit: 512 MB.