#LX0034. 关灯3
关灯3
题目描述
有一个的灯泡矩阵,一开始有的点是关(),有的点是开()。
你可以每次可以操作一行,或者一列,把这一行/列所有的灯的状态取反,这个操作可以无限次使用。
你还有次机会,每次可以把一个位置的灯取反。
问:请构造一个方案,把所有灯关闭,或者报告不可行。
。
Kitty has lights, which form an matrix.
One day, Kitty found that some of these lights were on, and some were off. Kitty wants to turn them all off.
To achieve her goal, Kitty can perform three types of operations:
-
(1) Choose a row, reverse the state of this row. It means if a light of this row is on, after this operation, it is now off. If a light of this row is off, after this operation, it is now on.
-
(2) Choose a column, reverse the state of this column. It means if a light of this column is on, after this operation, it is now off. If a light of this column is off, after this operation, it is now on.
-
(3) Choose exactly one light, reverse the state of this light. This operation can only be performed not more than times.
For the current state, help Kitty achieve her goal within operations.
输入格式
The first line contains two integers , indicating as described above.
Then lines follow, each line has exactly numbers, represents that the light is turned off at this time, while represents the opposite.
The -th number of the -th line in input means the light at coordinate .
输出格式
If Kitty can not achieve her goal,print in a single line.
Otherwise, print in the first line, indicating the number of operations she needs to perform.
The next lines, each line contains integers , separated by white space.
If , it means Kitty will reverse the light at coordinate .
If , it means Kitty will reverse all lights at coordinates .
If , it means Kitty will reverse all lights at coordinates .
If there are multiple answers, print any of them.
2 0
0 1
1 0
2
0 2
2 0
3 1
1 0 0
0 1 0
0 0 1
-1
相关
在以下作业中: