记录编号 19258 评测结果 AAAAAAAAAA
题目名称 魔术数字游戏 最终得分 100
用户昵称 GravatarDes. 是否通过 通过
代码语言 Pascal 运行时间 2.890 s
提交时间 2010-09-30 16:38:52 内存使用 0.11 MiB
显示代码纯文本
program magic;{Orz...This code is copied by a shen niu}
var x1,y1:integer;
  x,i,j:integer;
  a:array[1..16] of integer; first:boolean;
  a1,a2,a3,a5,a7,a9,a10:word;
function geti(x,y:integer):integer;
begin exit((x-1)*4+y); end;
function comply(i:integer):boolean;
var ii:integer;
begin
 comply:=false;
 if (a[i]<1) or (a[i]>16) then exit;
 for ii:=1 to i-1 do if a[ii]=a[i] then exit;
 if ((i<>x) and (a[i]=1)) or ((i=x) and (a[i]<>1)) then exit;
 comply:=true;
end;
begin
  assign(input,'magic.in'); reset(input);
  assign(output,'magic.out'); rewrite(output);
  readln(x1,y1);
  x:=(x1-1)*4+y1;
  first:=true;
 for a1:=1 to 16 do begin a[1]:=a1; if comply(1) then begin
  for a2:=1 to 16 do begin a[2]:=a2; if comply(2) then begin
   for a3:=1 to 16 do begin a[3]:=a3; if comply(3) then begin
    a[4]:=34-a[1]-a[2]-a[3]; if comply(4) then begin
     for a5:=1 to 16 do begin a[5]:=a5; if comply(5) then begin
      a[6]:=34-a[1]-a[2]-a[5]; if comply(6) then begin
       for a7:=1 to 16 do begin a[7]:=a7; if comply(7) then begin
        a[8]:=34-a[5]-a[6]-a[7]; if (a[3]+a[4]+a[7]+a[8]=34) and comply(8) then begin
         for a9:=1 to 16 do begin a[9]:=a9; if comply(9) then begin
          for a10:=1 to 16 do begin a[10]:=a10; if comply(10) then begin
           a[11]:=34-a[6]-a[7]-a[10]; if comply(11) then begin
            a[12]:=34-a[9]-a[10]-a[11]; if comply(12) then begin
             a[13]:=34-a[1]-a[5]-a[9]; if (a[4]+a[7]+a[10]+a[13]=34) and comply(13) then begin
              a[14]:=34-a[2]-a[6]-a[10]; if (a[9]+a[10]+a[13]+a[14]=34) and comply(14) then begin
               a[15]:=34-a[3]-a[7]-a[11]; if comply(15) then begin
                a[16]:=34-a[13]-a[14]-a[15];
if   (a[11]+a[12]+a[15]+a[16]=34)
 and (a[1]+a[4]+a[13]+a[16]=34)
 and (a[1]+a[6]+a[11]+a[16]=34)
 and comply(16) then begin
   if not first then writeln;
   first:=false;
   for i:=1 to 4 do begin for j:=1 to 3 do write(a[geti(i,j)],' '); writeln(a[geti(i,4)]);
end; end; end;
end; end; end;
end; end; end;
end; end; end;
end; end; end;
end; end; end;
end; end; end;
end; end; end;
  close(input); close(output);
end.