The method for solving the equation written in the previous post is incorrect!
Previous ugly methods:
First, use the row-column transformation to remove the element. If we find that all the coefficients related to the current I-th element are 0, we can directly determine it as a free element, skip this equation, ignore it completely, and then proceed, final return judgment without Solution
X
X xx x xx
X
X xxxx
X
X
However, the ugly program is actually AC on poj, and its data is too weak!
The random data generated by the user will be confused as soon as possible.
Positive Solution:
The row-column transformation is also used to remove the element. However, if we find that all coefficients related to the element I are 0, skip the element I. However, we cannot skip this equation, next time, we have to start from this equation to find the next element. The number of free elements is the number of redundant equations. As for the unsolvable formula, since non-redundant equations have eliminated all coefficients, therefore, you only need to check whether the equations are satisfied in the last several equations.
Code:
Program syj; {XOR equation} <br/> var task, I, J, K, Z, ANS, N: longint; <br/> A: array [1 .. 30] of longint; <br/> begin <br/> assign (input, 'switch. in '); reset (input); <br/> assign (output, 'switch. out'); rewrite (output); <br/> readln (task); <br/> for task: = 1 to task do begin <br/> readln (N ); <br/> for I: = 1 to n do read (A [I]); <br/> for I: = 1 to n do begin <br/> Read (j); A [I]: = A [I] XOR J; <br/> end; <br/> for I: = 1 to n do a [I]: = A [I] Or (1 <I); <br/> readln (I, j); <br/> while I + j> 0 do begin <br/> A [J]: = A [J] Or (1 <I ); <br/> readln (I, j); <br/> end; <br/> ans: = 0; K: = 1; <br/> for I: = 1 to n do begin <br/> for J: = K to n do if odd (A [J]> I) then begin <br/> Z: = A [k]; A [k]: = A [J]; A [J]: = z; break; <br/> end; <br/> if not odd (A [k]> I) Then Inc (ANS) <br/> else begin <br/> for J: = k + 1 to n do if odd (A [J]> I) then a [J]: = A [J] XOR A [k]; <br/> Inc (k); <br/> end; <br/> for I: = K to n do if odd (A [I]) then begin <br/> ans: =-1; break; <br/> end; <br/> If ans =-1 then writeln (0) <br/> else writeln (1 <ans); <br/> end; <br/> close (input); close (output); <br/> end. <br/>