TopCoder problem "SkewSymmetric" used in SRM 319 (Division II Level One)



Problem Statement

    

A skew symmetric matrix M satisfies MT = -M, where MT denotes the transpose of the matrix M and -M denotes the matrix obtained by multiplying each entry of M by -1. The transpose of a matrix M is obtained by replacing the element in the i'th row and j'th column of M with the element in the j'th row and i'th column of M. Note that this requires the diagonal elements of a skew-symmetric matrix to be equal to 0.

Create a class SkewSymmetric which contains a method minChanges. The method will take a String[] M, each element of which is a single space separated list of integers. The j'th number in the i'th element of M represents the value at row i and column j of the matrix. The method should return the minimum number of values in M that must be changed such that the resulting matrix is skew symmetric.

 

Definition

    
Class:SkewSymmetric
Method:minChanges
Parameters:String[]
Returns:int
Method signature:int minChanges(String[] M)
(be sure your method is public)
    
 

Constraints

-M will contain between 2 and 10 elements, inclusive.
-Each element of M will be a single space separated list of exactly n integers, where n is the number of elements in M.
-Each element of M will contain between 1 and 50 characters, inclusive.
-Each integer in M will be between -99 and 99 inclusive, with no extra leading zeros.
-The integer zero will be represented as '0' (quotes for clarity) only, and not '-0' (quotes for clarity) in M.
 

Examples

0)
    
{"1 2 8", "-2 1 0", "3 99 3"}
Returns: 5
One possible skew-symmetric matrix obtained by changing 5 elements in M is:
  0  2  -3
 -2  0 -99
  3 99   0
Note that the diagonal elements must be 0.
1)
    
{"0 1 1 1 1 1", "-1 0 1 1 1 1", "-1 -1 0 1 1 1", 
"-1 -1 -1 0 1 1", "-1 -1 -1 -1 0 1", "0 0 0 0 0 0"}
Returns: 5
2)
    
{"0 0 0 0", "0 0 0 0", "0 0 0 0", "0 0 0 0"}
Returns: 0
3)
    
{"1 0", "0 1"}
Returns: 2

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=6151

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=9999&pm=6151

Writer:

NeverMore

Testers:

PabloGilberto , brett1479 , Olexiy , ged

Problem categories:

Brute Force, Simple Math