NK05MNIM - Bốc sỏi

Tác giả: RR

Ngôn ngữ: Pascal

PROGRAM NK05MNIM;
CONST
  fi='';
  fo='';
  maxn=100;
VAR
  n,a,nsum:byte;
  f1,f2:text;
  kq:shortint;
Procedure OpenFiles;
Begin
  Assign(f1,fi); Reset(f1);
  Assign(f2,fo); Rewrite(f2);
End;
Procedure CloseFiles;
Begin
  Close(f1); Close(f2);
End;
Procedure Calculate;
Var
  i:byte;
  sl:byte;
Begin
  Readln(f1,n);
  sl:=0; nsum:=0;
  For i:=1 to n do
    begin
      Read(f1,a);
      If a>1 then inc(sl);
      nsum:=nsum xor a;
    end;
  If sl=0 then
    begin
      If n mod 2=0 then kq:=1
      else kq:=-1;
      exit;
    end;
  If sl=1 then
    begin
      kq:=1;
      exit;
    end;
  If nsum=0 then kq:=-1 else kq:=1;
End;
Procedure Solve;
Var
  t,i:byte;
Begin
  Readln(f1,t);
  For i:=1 to t do
    begin
      Calculate;
      Writeln(f2,kq);
    end;
End;
BEGIN
  OpenFiles;
  Solve;
  CloseFiles;
END.

Download