Description
The game "the pilots brothers: Following the stripy elephant" has a quest where a player needs to open a refrigerator.
There are 16 handles on the refrigerator door. every handle can be in one of two States: open or closed. the refrigerator is open only when all handles are open. the handles are represented as a matrix 4 records 4. you can change the state of a handle in any location[I, j](1 ≤ I, j ≤ 4). However, this also changes states of all handles in rowIAnd all handles in ColumnJ.
The task is to determine the minimum number of handle switching necessary to open the refrigerator.
Input
The input contains four lines. each of the four lines contains four characters describing the initial state of appropriate handles. A symbol "+" means that the handle is in closed state, whereas the symbol "?" Means "open". At least one of the handles is initially closed.
Output
The first line of the input contains N-the minimum number of switching. the rest n lines describe switching sequence. each of the lines contains a row number and a column number of the matrix separated by one or more spaces. if there are several solutions, you may give any one of them.
Sample Input
-+-----------+--
Sample output
61 11 31 44 14 34 4
Solution:
Er... This question is classified by the author as BFS and DFS. If you think about this question carefully, you can find out the rule. If a refrigerator door changes its status, its row and column must change its status. Only the door with an odd number of changes can change its status, the door with an even number of changes will return to the previous state. Therefore, we only need to change the odd number of times as a change, but we have never changed the number of times. When one of the points needs to be changed, each point in the column where the point is located is changed once, and the points to be changed are changed seven times in total, the other vertices in this column in this row are changed only four times, and the remaining vertices are changed only two times, even times, which is equivalent to no change.
AC code:
# Include <iostream> # include <cstdio> # include <cstring> using namespace STD; const int maxn = 10; int main () {char map [maxn] [maxn]; int count [maxn] [maxn], total = 0; // count is used to record the number of changes to each vertex memset (count, 0, sizeof (count )); for (INT I = 0; I <4; I ++) {for (Int J = 0; j <4; j ++) {scanf ("% C ", & map [I] [J]); If (Map [I] [J] = '+ ') // change all vertices in the row and column if needed {for (int K = 0; k <4; k ++) count [I] [k] ++; For (int K = 0; K <4; k ++) Count [k] [J] ++; count [I] [J] --; // point (I, j) changed twice, minus one} getchar () ;}for (INT I = 0; I <4; I ++) for (Int J = 0; j <4; j ++) if (count [I] [J] % 2! = 0) // If the odd number is changed, the total ++ is changed once. // The total number of printf ("% d \ n", total) is changed several times ); for (INT I = 0; I <4; I ++) for (Int J = 0; j <4; j ++) if (count [I] [J] % 2! = 0) printf ("% d \ n", I + 1, J + 1); // output the coordinate return 0 ;}
The pilots brothers 'refrigerator