#abc322d. D - Polyomino
D - Polyomino
当前没有测试数据。
Score : points
问题描述
多米诺骨牌是一种由多个正方形通过边相连形成的连通多边形形状的拼图碎片。
有一个4行4列的网格,以及三个适合放入该网格的多米诺骨牌。
第个多米诺骨牌的形状由16个字符()表示。它们描述了当第个多米诺骨牌放置在网格上时的状态。如果为#
,表示从上到下第行、从左到右第列的格子被该多米诺骨牌占据;如果是.
,则表示该格子未被占据。(请参考示例输入/输出1中的图例。)
你需要将这三个多米诺骨牌填入网格中,以满足以下所有条件:
- 网格中的所有格子都被多米诺骨牌覆盖。
- 多米诺骨牌之间不能重叠。
- 多米诺骨牌不能超出网格范围。
- 多米诺骨牌可以自由平移和旋转,但不能翻转。
能否通过调整多米诺骨牌的位置和方向,使得网格能够满足上述条件被填满?
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
A polyomino is a puzzle piece in the shape of a connected polygon made by connecting several squares by their edges.
There is a grid with four rows and four columns, and three polyominoes that fit within the grid.
The shape of the -th polyomino is represented by characters (). They describe the state of the grid when the -th polyomino is placed on it. If is #
, the square at the -th row from the top and -th column from the left is occupied by the polyomino; if it is .
, the square is not occupied. (Refer to the figures at Sample Input/Output .)
You want to fill the grid with all three polyominoes so that all of the following conditions are satisfied.
- All squares of the grid are covered by the polyominoes.
- The polyominoes must not overlap each other.
- The polyominoes must not stick out of the grid.
- The polyominoes may be freely translated and rotated but may not be flipped over.
Can the grid be filled with the polyominoes to satisfy these conditions?
Constraints
- is
#
or.
. - The given polyominoes are connected. In other words, the squares that make up a polyomino can be reached from each other by following only the squares up, down, left, and right.
- The given polyominoes are not empty.
Input
The input is given from Standard Input in the following format:
Output
If it is possible to fill the grid with the polyominoes to satisfy the conditions in the problem statement, print Yes
; otherwise, print No
.
Sample Input 1
....
###.
.#..
....
....
.###
.##.
....
..#.
.##.
.##.
.##.
Sample Output 1
Yes
The figure below shows the shapes of the polyominoes corresponding to Sample Input .
In this case, you can fill the grid with them to satisfy the conditions in the problem statement by placing them as shown in the figure below.
Thus, the answer is Yes
.
Sample Input 2
###.
#.#.
##..
....
....
..#.
....
....
####
##..
#...
#...
Sample Output 2
Yes
As in the first polyomino in Sample Input , a polyomino may be in the shape of a polygon with a hole.
Sample Input 3
##..
#..#
####
....
....
##..
.##.
....
.#..
.#..
.#..
.#..
Sample Output 3
No
Note that the polyominoes may not be flipped over when filling the grid.
Sample Input 4
....
..#.
....
....
....
..#.
....
....
....
..#.
....
....
Sample Output 4
No
Sample Input 5
....
####
#...
#...
....
####
...#
..##
....
..##
..#.
..##
Sample Output 5
No
Sample Input 6
###.
.##.
..#.
.###
....
...#
..##
...#
....
#...
#...
#...
Sample Output 6
Yes