#P1985. [USACO07OPEN] 翻转棋 Fliptile S
[USACO07OPEN] 翻转棋 Fliptile S
Description
FJ knows that cows with higher IQ produce more milk, so he prepared a tile-flipping puzzle for them.
On an grid (), each cell has a tile that can be flipped. One side of a tile is black, the other side is white. Flipping a tile toggles its color between black and white.
However, the cows are clumsy: when they flip the tile in a cell, all tiles that share an edge with it also flip.
Now they want to know the minimum number of flips needed to make all tiles face white up.
Input Format
The first line contains two integers .
Then follow lines, each with integers, describing the initial state: means white side up, means black side up.
Output Format
If it is impossible to make all tiles white side up, output IMPOSSIBLE.
Otherwise, output lines, each with integers; the number at row , column denotes how many times the tile at row , column is flipped.
Your output must have the minimum total number of flips. If there are multiple solutions, output the lexicographically smallest one.
Here, lexicographically smallest means the string formed by removing all whitespace from your output is lexicographically smallest.
4 4
1 0 0 1
0 1 1 0
0 1 1 0
1 0 0 1
0 0 0 0
1 0 0 1
1 0 0 1
0 0 0 0
Hint
The following solution also has the minimum number of operations, but it is not lexicographically smallest.
0 1 1 0
0 0 0 0
0 0 0 0
0 1 1 0
Translated by ChatGPT 5
京公网安备 11011102002149号