102182: [AtCoder]ABC218 C - Shapes

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $300$ points

Problem Statement

We have two figures $S$ and $T$ on a two-dimensional grid with square cells.

$S$ lies within a grid with $N$ rows and $N$ columns, and consists of the cells where $S_{i,j}$ is #.
$T$ lies within the same grid with $N$ rows and $N$ columns, and consists of the cells where $T_{i,j}$ is #.

Determine whether it is possible to exactly match $S$ and $T$ by $90$-degree rotations and translations.

Constraints

  • $1 \leq N \leq 200$
  • Each of $S$ and $T$ consists of # and ..
  • Each of $S$ and $T$ contains at least one #.

Input

Input is given from Standard Input in the following format:

$N$
$S_{1,1}S_{1,2}\ldots S_{1,N}$
$\vdots$
$S_{N,1}S_{N,2}\ldots S_{N,N}$
$T_{1,1}T_{1,2}\ldots T_{1,N}$
$\vdots$
$T_{N,1}T_{N,2}\ldots T_{N,N}$

Output

Print Yes if it is possible to exactly match $S$ and $T$ by $90$-degree rotations and translations, and No otherwise.


Sample Input 1

5
.....
..#..
.###.
.....
.....
.....
.....
....#
...##
....#

Sample Output 1

Yes

We can match $S$ to $T$ by rotating it $90$-degrees counter-clockwise and translating it.


Sample Input 2

5
#####
##..#
#..##
#####
.....
#####
#..##
##..#
#####
.....

Sample Output 2

No

It is impossible to match them by $90$-degree rotations and translations.


Sample Input 3

4
#...
..#.
..#.
....
#...
#...
..#.
....

Sample Output 3

Yes

Each of $S$ and $T$ may not be connected.


Sample Input 4

4
#...
.##.
..#.
....
##..
#...
..#.
....

Sample Output 4

No

Note that it is not allowed to rotate or translate just a part of a figure; it is only allowed to rotate or translate a whole figure.

Input

题意翻译

给定两个 $N \times N$ 大小的矩阵 $S,T$,问能不能将 $S$ 通过**不限次** $90\degree$ 旋转和**不限次**平移得到 $T$,如果能,输出 `Yes`,否则输出 `No`。

Output

分数:300分 部分 问题描述 我们在二维网格上有两个图形S和T,网格由正方形单元格组成。 S位于一个具有N行和N列的网格内,由S_{i,j}是 "#" 的单元格组成。 T位于具有相同N行和N列的网格内,由T_{i,j}是 "#" 的单元格组成。 确定是否可以通过90度旋转和平移精确匹配S和T。 部分 约束条件 1≤N≤200 S和T都由 "#" 和 "." 组成。 S和T都至少包含一个 "#"。 输入输出格式 输入 输入格式如下: $N$ $S_{1,1}S_{1,2}\ldots S_{1,N}$ $\vdots$ $S_{N,1}S_{N,2}\ldots S_{N,N}$ $T_{1,1}T_{1,2}\ldots T_{1,N}$ $\vdots$ $T_{N,1}T_{N,2}\ldots T_{N,N}$ 输出 如果可以通过90度旋转和平移精确匹配S和T,则打印"Yes",否则打印"No"。 样例 样例输入1 5 ..... ..#.. .###. ..... ..... ..... ..... ....# ...## ....# 样例输出1 Yes 我们可以通过将S逆时针旋转90度并将其平移来匹配T。 样例输入2 5 ##### ##..# #..## ##### ..... ##### #..## ##..# ##### ..... 样例输出2 No 无法通过90度旋转和平移来匹配它们。 样例输入3 4 #... ..#. ..#. .... #... #... ..#. .... 样例输出3 Yes S和T可能不相连。 样例输入4 4 #... .##. ..#. .... ##.. #... ..#. .... 样例输出4 No 请注意,仅允许旋转或平移整个图形,而不允许仅旋转或平移图形的一部分。

加入题单

算法标签: