记录编号 19318 评测结果 AAAAATATTT
题目名称 魔术数字游戏 最终得分 60
用户昵称 Gravatar1102 是否通过 未通过
代码语言 Pascal 运行时间 5.912 s
提交时间 2010-10-08 10:32:34 内存使用 0.11 MiB
显示代码纯文本
program xxxx;
var a:array[1..5,1..5] of integer;
    m,n,j,j1,z:integer;
    pd:array[2..16] of boolean;



function panduan(x,y,i:integer):boolean;
var p,m:integer;
begin
  m:=0;
  if a[x,y]<>1 then
    a[x,y]:=i;
  if y=4 then
    begin
      for p:=1 to 4 do
        m:=m+a[x,p];
      if m<>34 then
        begin
          panduan:=false;
          a[x,y]:=0;
          exit;
        end;
      m:=0;
    end;
  if x=4 then
    begin
      for p:=1 to 4 do
        m:=m+a[p,y];
      if m<>34 then
        begin
          panduan:=false;
          a[x,y]:=0;
          exit;
        end;
      m:=0;
    end;
  if (x mod 2=0)and(y mod 2=0) then
    if a[x,y]+a[x-1,y]+a[x,y-1]+a[x-1,y-1]<>34 then
      begin
        panduan:=false;
        a[x,y]:=0;
        exit;
      end;
  if (x=3)and(y=3) then
    if a[2,2]+a[3,3]+a[2,3]+a[3,2]<>34 then
      begin
        panduan:=false;
        a[x,y]:=0;
        exit;
      end;
  if (x=4)and(y=1) then
    if a[4,1]+a[3,2]+a[2,3]+a[1,4]<>34 then
      begin
        panduan:=false;
        a[x,y]:=0;
        exit;
      end;
  if (x=4)and(y=4) then
    if (a[4,4]+a[3,3]+a[2,2]+a[1,1]<>34)
    and(a[1,4]+a[1,1]+a[4,1]+a[4,4]<>34)then
      begin
        panduan:=false;
        a[x,y]:=0;
        exit;
      end;
  panduan:=true;
end;



procedure work(x,y:integer);
var i,j:integer;
begin
  if x=5 then
    begin
      inc(z);
      for i:=1 to 4 do
        begin
          for j:=1 to 4 do
            write(a[i,j],' ');
          writeln;
        end;
      writeln;
      //halt;

    end
  else
    begin
      if a[x,y]<>0 then
        begin
          if y+1=5 then
            work(x+1,1)
          else
            work(x,y+1);
        end
      else
      for i:=2 to 16 do
        begin
          if pd[i]=true then
            begin
             if (panduan(x,y,i)=true) then
               begin
                 if a[x,y]<>1 then
                   begin
                     a[x,y]:=i;
                     pd[i]:=false;
                     if y+1=5 then
                       work(x+1,1)
                     else
                       work(x,y+1);
                     pd[i]:=true;
                     a[x,y]:=0;
                   end
                 else
                   begin
                     if y+1=5 then
                       work(x+1,1)
                     else
                       work(x,y+1);
                   end;
               end;
            end;
        end;

    end;
end;


begin
  assign(input,'magic.in');
  reset(input);
  assign(output,'magic.out');
  rewrite(output);
  read(m,n);
  for j:=1 to 4 do
    for j1:=1 to 4 do
      a[j,j1]:=0;
  for j:=2 to 16 do
    pd[j]:=true;
  a[m,n]:=1;
  work(1,1);
  close(input);
  close(output);
end.