比赛 20100927 评测结果 AAAAAAAATA
题目名称 魔术数字游戏 最终得分 90
用户昵称 wo shi 刘畅 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-09-27 20:56:07
显示代码纯文本
var
  m,n:longint;
  g:longint;
  a:array[0..5,0..5]of longint;
  f:array[0..20]of boolean;

procedure print;
var
  i,j:longint;
begin
  inc(g);
  if g>1 then writeln;
    for i:=1 to 3 do
    begin
      for j:=1 to 3 do
      write(a[i,j],' ');
      writeln(a[i,4]);
    end;
    for i:=1 to 3 do
    write(a[4,i],' ');
    write(a[4,4]);
end;

function hang(k:longint):boolean;
var
  i,t:longint;
begin
  t:=0;
  for i:=1 to 4 do inc(t,a[k,i]);
  if t=34 then exit(true);
  exit(false);
end;

function lie(k:longint):boolean;
var
  i,t:longint;
begin
  t:=0;
  for i:=1 to 4 do inc(t,a[i,k]);
  if t=34 then exit(true);
  exit(false);
end;

function you:boolean;
var
  i,t:longint;
begin
  t:=0;
  for i:=1 to 4 do inc(t,a[i,4-i+1]);
  if t=34 then exit(true);
  exit(false);
end;

function zuo:boolean;
var
  i,t:longint;
begin
  t:=0;
  for i:=1 to 4 do inc(t,a[i,i]);
  if t=34 then exit(true);
  exit(false);
end;

function jiao:boolean;
var
  i,t:longint;
begin
  t:=0;
  inc(t,a[1,1]);
  inc(t,a[1,4]);
  inc(t,a[4,1]);
  inc(t,a[4,4]);
  if t=34 then exit(true);
  exit(false);
end;

function zhong:boolean;
var
  i,t:longint;
begin
  t:=0;
  inc(t,a[2,2]);
  inc(t,a[2,3]);
  inc(t,a[3,2]);
  inc(t,a[3,3]);
  if t=34 then exit(true);
  exit(false);
end;

function zs:boolean;
var
  t:longint;
begin
  t:=0;
  inc(t,a[1,1]);
  inc(t,a[1,2]);
  inc(t,a[2,1]);
  inc(t,a[2,2]);
  if t=34 then exit(true);
  exit(false);
end;

function ys:boolean;
var
  t:longint;
begin
  t:=0;
  inc(t,a[1,3]);
  inc(t,a[1,4]);
  inc(t,a[2,3]);
  inc(t,a[2,4]);
  if t=34 then exit(true);
  exit(false);
end;

function zx:boolean;
var
  t:longint;
begin
  t:=0;
  inc(t,a[3,1]);
  inc(t,a[3,2]);
  inc(t,a[4,1]);
  inc(t,a[4,2]);
  if t=34 then exit(true);
  exit(false);
end;

function yx:boolean;
var
  t:longint;
begin
  t:=0;
  inc(t,a[3,3]);
  inc(t,a[3,4]);
  inc(t,a[4,3]);
  inc(t,a[4,4]);
  if t=34 then exit(true);
  exit(false);
end;

procedure go(x,y:longint);
var
  i,j:longint;
begin
  if x=5 then
  begin
    print;
    writeln;
    exit;
  end;
  if a[x,y]=1 then
  begin
    if (y=4)and(not hang(x)) then exit;

    if (x=2)and(y=2)and(not zs) then exit;

    if (x=2)and(y=4)and(not ys) then exit;

    if (x=3)and(y=3)and(not zhong) then exit;

    if (x=4)and(y=2)and(not zx) then exit;

    if (x=4)and(y=4)and(not yx) then exit;

    if (x=4)and(not lie(y)) then exit;
    if (x=4)and(y=1)and(not you) then exit;
    if (x=4)and(y=4) then
    begin
      if not zuo then exit;
      if not jiao then exit;
    end;
    if y=4 then go(x+1,1)
    else go(x,y+1);
  end

  else for i:=2 to 16 do
  if not f[i] then
  begin
    a[x,y]:=i;
    if (y=4)and(not hang(x)) then continue;

    if (x=2)and(y=2)and(not zs) then continue;

    if (x=2)and(y=4)and(not ys) then continue;

    if (x=3)and(y=3)and(not zhong) then continue;

    if (x=4)and(y=2)and(not zx) then continue;

    if (x=4)and(y=4)and(not yx) then continue;

    if (x=4)and(not lie(y)) then continue;
    if (x=4)and(y=1)and(not you) then continue;
    if (x=4)and(y=4) then
    begin
      if not zuo then continue;
      if not jiao then continue;
    end;
    f[i]:=true;
    if y=4 then go(x+1,1)
    else go(x,y+1);
    f[i]:=false;
  end;
end;

begin
  assign(input,'magic.in'); reset(input);
  assign(output,'magic.out'); rewrite(output);
  readln(m,n);
  a[m,n]:=1;
  g:=0;
  f[1]:=true;
  go(1,1);
  close(input);
  close(output);
end.