Topic links
Test Instructions: a refrigerator has 4*4 a total of 16 switches, changing the state of any switch (that is, turn on and off, turn on), the same line of this switch, the same column all the switches will automatically change the state. If you want to open the refrigerator, all the switches can be opened. input: A 4x4 matrix, + indicates off,-Indicates open, output: The minimum number of operations required to open the refrigerator, and the switching coordinates of the operation.
Key: The core is actually, the switch itself and its same row of the same column of switches (a total of 7) to perform one operation, the result is that the switch itself state changed 7 times, switch the same row, the same column of the switch state changed 4 times, the other switch status changed 2 times. This is equivalent to changing only the state of itself.
Code:
#include <iostream>#include<cstdio>#include<cmath>#include<cstring>#include<algorithm>#include<queue>using namespacestd;intMain () {CharC; inta[Ten][Ten]; Memset (A,0,sizeof(a)); for(intI=0;i<4; i++) for(intj=0;j<4; j + +) {cin>>C; if(c=='+') { for(intk=0;k<4; k++) {A[i][k]++; A[K][J]++; } A[i][j]--; } } intsum=0; for(intI=0;i<4; i++) for(intj=0;j<4; j + +) if(a[i][j]%2) sum++; printf ("%d\n", sum); for(intI=0;i<4; i++) for(intj=0;j<4; j + +) if(a[i][j]%2) printf ("%d%d\n", i+1, j+1); return 0;}
POJ 2965 the pilots ' refrigerator