Editorial for M & M Game


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Lưu ý: Các code mẫu dưới đây chỉ mang tính tham khảo và có thể không AC được bài tập này

Code mẫu của flashmt

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.

Code mẫu của happyboy99x

#include<bits/stdc++.h>
using namespace std;

int main() {
    int t; cin >> t;
    while(t--) {
        int res = 0, n, mx = 0; cin >> n;
        for(int i = 0, x; i < n; ++i) cin >> x, res ^= x, mx = max(mx, x);
        cout << ((mx <= 1) != (res == 0) ? "Brother" : "John") << endl;
    }
    return 0;
}

Code mẫu của ladpro98

#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <cassert>

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, a, b) for(int i = (a); i <=(b); ++i)
#define FORD(i, a, b) for(int i = (a); i > (b); --i)
#define REPD(i, a, b) for(int i = (a); i >=(b); --i)
#define TR(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define RESET(a, v) memset(a, (v), sizeof(a))
#define SZ(a) (int(a.size()))
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define LL long long
#define LD long double
#define II pair<int, int>
#define X first
#define Y second
#define VI vector<int>
#define VII vector<II>
#define endl '\n'

using namespace std;

int nTest, n, x;

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  #ifdef _LAD_
    freopen("MMMGAME.in", "r", stdin);
  #endif // _LAD_
  cin >> nTest;
  while (nTest--) {
    cin >> n;
    int sumXor = 0, cntOne = 0;
    int nn = n;
    while (nn--) {
      cin >> x;
      sumXor ^= x;
      if (x == 1) cntOne++;
    }
    if (cntOne == n)
      cout << ((cntOne & 1) ? "Brother" : "John") << endl;
    else
      cout << (sumXor ? "John" : "Brother") << endl;
  }
  return 0;
}

Code mẫu của RR

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;
      if kq=-1 then Writeln(f2,'Brother') else writeln(f2,'John');
    end;
End;
BEGIN
  OpenFiles;
  Solve;
  CloseFiles;
END.

Code mẫu của hieult

#include <stdio.h>
//#include <conio.h>
main()
{
long a[101],T,n,a1,c[15];
scanf("%ld",&T);
for(long i=1;i<=T;i++)
  {
  scanf("%ld",&n);
  a1=0;
  for(long j=1;j<=n;j++)
    {
    scanf("%ld",&a[j]);
    if(a[j]==1)
      a1++;
    }
  if(a1==n)
    {
    if(n%2!=0)
      printf("Brother\n");
    else printf("John\n");
    }
  else if(a1==n-1)
    printf("John\n");
  else
    {
    long max=0;
    long t=0;
    long kt=-1;                 
    for(long j=1;j<=n;j++)
      if(a[j]>max)
        max=a[j];
    while(max!=0)
      {
      t++; max=max/2;
      }
    //printf("%ld ",t);  
    for(long j=1;j<=t;j++)
      c[j]=0;  
    for(long j=1;j<=n;j++)
      for(long k=1;k<=t;k++)
        {
        c[k]=c[k]+a[j]%2;
        a[j]=a[j]/2;
        }
    for(long j=1;j<=t;j++)
       if(c[j]%2!=0)
         {
         kt=1;
         break;
         }
    if(kt==1)
      printf("John\n");
    else printf("Brother\n");
    }
  }  
//getch();
}

Code mẫu của ll931110

{$MODE DELPHI}
Program MMMGAME;
Const
  input  = '';
  output = '';
Var
  fi,fo: text;
  t,i: integer;

Procedure openfile;
Begin
  Assign(fi, input);
    Reset(fi);

  Assign(fo, output);
    Rewrite(fo);
End;

Procedure solve;
Var
  n,i,k,res: integer;
  win1,win2,c1,c2,fin: boolean;
Begin
  res:= 0;
  win1:= true;

  c1:= false;
  c2:= false;

  Readln(fi, n);
  For i:= 1 to n do
    Begin
      Read(fi, k);
      If k = 1 then
        Begin
          c1:= true;
          win1:= not win1;
        End else c2:= true;
      res:= res xor k;
    End;

       If not c2 then fin:= win1
  else if not c1 then fin:= not (res = 0)
  else
    fin:= not (res = 0);

  If fin then writeln(fo, 'John') else writeln(fo, 'Brother');
End;

Procedure closefile;
Begin
  Close(fo);
  Close(fi);
End;

Begin
  openfile;

  Readln(fi, t);
  For i:= 1 to t do solve;

  closefile;
End.

Comments

Please read the guidelines before commenting.


There are no comments at the moment.