MMMGAME - M & M Game

Tác giả: flashmt

Ngôn ngữ: Pascal

const fi='';
      fo='';
      max=12;
var t,j,k:longint;
    n,p,i:byte;
    a:array[1..4747,0..max] of byte;
    re:array[0..max] of byte;
    kt1:boolean;

procedure init;
var i,t:integer; j:byte;
begin
     fillchar(a,sizeof(a),0);
     for i:=1 to 4747 do
     begin
          t:=i;
          j:=0;
          while t>0 do
          begin
               a[i,j]:=t mod 2;
               t:=t div 2;
               inc(j);
          end;
     end;
end;

function check:Boolean;
var i:byte; kt:boolean;
begin
     kt:=false;
     for i:=0 to max do
         if re[i]=1 then
         begin
              kt:=true;
              break;
         end;
     check:=kt;
end;

begin
     assign(input,fi);
     reset(input);
     assign(output,fo);
     rewrite(output);
     init;
     readln(t);
     for j:=1 to t do
     begin
          readln(n);
          kt1:=true;
          fillchar(re,sizeof(re),0);
          for i:=1 to n do
          begin
               read(k);
               if k<>1 then kt1:=false;
               for p:=0 to max do re[p]:=(re[p]+a[k,p]) mod 2;
          end;
          if kt1 then
          begin
               if n mod 2 = 0 then writeln('John')
               else writeln('Brother');
          end
          else
          begin
               if check then writeln('John')
               else writeln('Brother');
          end;
     end;
     close(input);
     close(output);
end.

Download