Home » Java » POJ2965, recursive!

this problem is not difficult, there are many ways to achieve, however, after looking at the end of the report, I understand a kind of! Here, paste java code for reference only!

!

`import java.util.Scanner;**The subject is as follows:4*4 has a total of 16 switches of a refrigerator, change an arbitrary state of a switch (open into a closed, closed, open the switch into) the same line, the same row all switches will automatically change the state. To open the refrigerator, all to switch all open it.Input: a 4 * 4 matrix + + means "off" - means "open";Output: the minimum number of operations required to open the refrigerator, and the switch coordinates to be operated+ off state- open statusFind the minimum step in the 4*4 board to adjust to the full open state, and output the coordinates to be adjustedEven operations equal to 0 operations,An odd number operation is equal to 1 operationsTherefore, the number of operations per switch is one time** * /Public, class, poj2965 {Static boolean[][] visited = new boolean;Static char[][] map;Static int[] is=new int;Static int[] js=new int;Public, static, void, main (String[], args) {Auto-generated method stub / / TODOScanner SC = new Scanner (System.in);String[] old = new String;For (int i = 0; I < old.length; i++) {Old[i] = sc.nextLine ();}Map = new char;For (int i = 0; I < old.length; i++) {Map[i] = old[i].toCharArray ();}Caozuo (map);Int count = 0;For (int, I = 0, I, < 4, i++) {For (int, j = 0, J, < 4, j++) {If (visited[i][j]) {Is[count]=i+1;Js[count]=j+1;Count++;}}}System.out.println (count);For (int i = 0; I < count; i++) {System.out.println (is[i]+ "" +js[i] ");}}Private, static, void, SOP (int[][], ARR) {Auto-generated method stub / / TODOFor (int, I = 0, I, < 4, i++) {For (int, j = 0, J, < 4, j++) {System.out.print (arr[i][j]);}System.out.println ();}}Private, static, void, caozuo (char[][], map) {Auto-generated method stub / / TODOFor (int, I = 0, I, < 4, i++) {For (int, j = 0, J, < 4, j++) {If (map[i][j] = = ' +' t)Visited[i][j] = = visited[i][j];For (int, k = 0, K, < 4, k++) {Visited[i][k] = = visited[i][k];Visited[k][j] = = visited[k][j];}}}}}}`