Find correct positions in the Matrix

0

I am having difficulties with this reasoning. I have a 4x4 array. I should fill it with 0 and 1 as long as the number 1 appears twice in each row and in each column, as in the example below.

1   1   0   0       
1   0   0   1       
0   0   1   1       
0   1   1   0

But the situation below may occur. Then I would have to move the "1" from (2,3) to (4,2) which will return to the same as above.

1   1   0   0       
1   0   1   1       
0   0   1   1       
0   0   1   0

If I add the rows and columns, I can identify which row and column is wrong, but I can not make my program identify the exact position.

I need to give a return of type "move from (2,3) to (4,2) ". How can my program find the exact positions?

    
asked by anonymous 12.10.2014 / 05:28

1 answer

3
  

If I add the rows and columns, I can identify which row and column   is wrong, but I can not make my program identify the position   exact.

A: yes, logic is really adding each row and column, if the sum is greater than two (2) you will know the position of the row, column with more values or where it has more 1's than it should , you should move to the position where the sum is less than two (2) this tells you exactly where is missing number 1, following its example the logic would be as follows:

For this array:

1   1   0   0       
1   0   1   1       
0   0   1   1       
0   0   1   0

Let's start by adding all the lines first!

Add the first line of the Matrix:

1   1   0   0  ==> soma == 2 (OK)

Add the second line of the Matrix:

1   0   1   1  ==> soma == 3 (segunda linha da matriz com problema tem número a mais) > 2 

Third Matrix row:

0   0   1   1  ==> soma == 2 (OK)

Fourth Matrix row:

0   0   1   0  ==> soma ==  1 (quarta linha da matriz com problema tem número a menos) <2

Time to add columns:

First column:

1        
1          ==> soma == 2 (OK)
0          
0  

Second column:

1        
0        ==> soma == 1 (problema) < 2
0       
0 

Third column:

0        
1        ==> soma == 3 (problema) > 2
1         
1

Fourth column:

0       
1       ==> soma == 2 (OK)
1       
0
Now notice which line and column has a sum greater than two (> 2), it's going to be exactly the second line and the third column position (2,3) you have just found the positions with wrong values where you have more 1's than you should Now, to find which position to move to, note which position is less than two (< 2) you will notice that it will be the fourth line and second column (4,2) , there is a logical way to get to result!

    
12.10.2014 / 06:48