ACM-ICPC World Finals 2017 G

介绍了一种新型的自动细胞制造公司研发的大规模复制相同部件的方法。该过程使用二维格子结构,每个单元格有两种状态:空或填充。在复制过程中,如果九个相邻单元中有奇数个被填充,则当前单元将在下一时刻变为填充状态;否则为空状态。然而,在实际操作中存在单元格状态自发翻转的问题,这可能导致最终图案与预期不符。本文探讨了如何从可能已损坏的最终图案中逆向寻找最小的初始图案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Replicate Replicate Rfplicbte

The owner of the Automatic Cellular Manufacturing corporation has just patented a new process for the mass production of identical parts. Her approach uses a two-dimensional lattice of two-state cells, each of which is either “empty” or “filled.” The exact details are, of course, proprietary.

Initially, a set of cells in the lattice is filled with a copy of the part that is to be reproduced. In a sequence of discrete steps, each cell in the lattice simultaneously updates its state by examining its own state and those of its eight surrounding neighbors. If an odd number of these nine cells are filled, the cell’s state in the next time step will be filled, otherwise it will be empty. Figure 1 shows several steps in the replication process for a simple pattern consisting of three filled cells.

\includegraphics[width=1.0\textwidth ]{fig1}

Figure 1: The replication process.

However, a bug has crept into the process. After each update step, one cell in the lattice might spontaneously flip its state. For instance, Figure 2 shows what might happen if a cell flipped its state after the first time step and another flipped its state after the third time step.

\includegraphics[width=1.0\textwidth ]{fig2}

Figure 2: Errors in the replication process. This figure corresponds to Sample Input 1.

Unfortunately, the original patterns were lost, and only the (possibly corrupted) results of the replication remain. Can you write a program to determine a smallest possible nonempty initial pattern that could have resulted in a given final pattern?

Input

The first line of input contains two integers [Math Processing Error]w ([Math Processing Error]1≤w≤300) and [Math Processing Error]h ([Math Processing Error]1≤h≤300), where [Math Processing Error]w and [Math Processing Error]h are the width and height of the bounding box of the final pattern. Following that are [Math Processing Error]h lines, each containing [Math Processing Error]w characters, giving the final pattern. Each character is either ‘.’  (representing an empty cell) or ‘#’ (representing a filled cell). There is at least one filled cell in the first row, in the last row, in the first column, and in the last column.

Output

Display a minimum-size nonempty pattern that could have resulted in the given pattern, assuming that at each stage of the replication process at most one cell spontaneously changed state. The size of a pattern is the area of its bounding box. If there is more than one possible minimum-size nonempty starting pattern, any one will be accepted. Use the character ‘.’ for empty cells and ‘#’ for filled cells. Use the minimum number of rows and columns needed to display the pattern.

Sample Input 1Sample Output 1
10 10
.#...#...#
##..##..##
##.#.##...
##.#.##...
.#...#####
...##..#.#
......###.
##.#.##...
#..#..#..#
##..##..##
.#
##
Sample Input 2Sample Output 2
8 8
##..#.##
#.####.#
.#.#.#..
.##.#.##
.#.#.#..
.##.#.##
#..#.###
##.#.##.
####
#..#
#.##
###.
Sample Input 3Sample Output 3
5 4
#....
..###
..###
..###
#
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值