We have a grid of size Nx N. Each cell of the grid initially contains a zero(0) or a one(1).
The parity of a cell is the number of 1s surrounding that cell. A cell is surrounded by at most 4 cells (top, bottom, left, right).
Suppose we have a grid of size 4x 4:
| 1 |
0 |
1 |
0 |
The parity of each cell would be |
1 |
3 |
1 |
2 |
| 1 |
1 |
1 |
1 |
2 |
3 |
3 |
1 |
|
| 0 |
1 |
0 |
0 |

给定一个NxN的网格,初始状态下每个单元格包含0或1。单元格的奇偶性是由其周围1的数量决定的。任务是将0变为1,使每个单元格的奇偶性变为偶数,输出实现这一目标所需的最小翻转次数。如果无法达成,则输出-1。
最低0.47元/天 解锁文章
2万+

被折叠的 条评论
为什么被折叠?



