Problem 471: Alice and Bob

http://www.gdfzoj.com/oj/problem/471

分奇数和偶数层
要将奇数层推到偶数
偶数再到奇数
所以将所有与n同奇偶的层的数进行一个异或
故要改变一个数将剩下的异或值改为0;
所以a[i,jnew =a[i,j] xor q;
(1) 向下移
如果在最后一层 +1
否则+2
(2)从上向下移
不在顶层 +1

var a:array[0..20,0..40000] of longint;
    b:array[1..50] of longint;
    i,j,k,l,m,n,q,w,t:longint;
begin
    b[1]:=1; for i:=2 to 20 do b[i]:=b[i-1]*2;
    readln(t);
    for k:=1 to t do begin
        readln(n);
        l:=0; q:=0;
        fillchar(a,sizeof(a),0);
        for i:=1 to n do begin
            for j:= 1 to b[i] do read(a[i,j]);
            readln;
        end;
        for i:=1 to n do
           if (i mod 2)=(n mod 2) then
              for j:=1 to b[i] do q:=q xor a[i,j];
        for i:=1 to n do begin
            if (i mod 2)=(n mod 2) then
              for j:=1 to b[i] do begin
                  w:=q;
                  w:=w xor a[i,j];
                    if (a[i,j]>w)and(i=n) then l:=l+1;
                    if (a[i,j]>w)and(i<>n) then l:=l+2;
                    if (a[i,j]and(a[i-1,(j+1)div 2]+a[i,j]>=w)
                    and(i<>1)and(w<>a[i,j])then l:=l+1;
                  end;
        end;
        writeln(l);
    end;
end.

你可能感兴趣的:(sg)