比赛 |
20100927 |
评测结果 |
TTTTTTTTTT |
题目名称 |
魔术数字游戏 |
最终得分 |
0 |
用户昵称 |
Des. |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2010-09-27 22:28:39 |
显示代码纯文本
program magic;
var a:array[1..4,1..4]of integer;
b:array[1..16]of integer;
j2,j4,j5:array[1..4]of integer;
t,k,m,n,i,j,j1,j3,j6,j7,x,y:longint;
procedure sou(x,y:longint);
var t,k,x1,y1:longint;
begin
writeln(X,' ',Y);
if (x=5)and(y=1) then
begin
if (j1=34)and(j2[1]=34)and(j2[2]=34) and(j2[3]=34)and(j2[4]=34)
and (j3=34)and(j4[1]=34) and(j4[2]=34) and(j4[3]=34) and(j4[4]=34)
and (j6=34)and(j7=34)and(j5[1]=34) and(j5[2]=34) and(j5[3]=34) and(j5[4]=34) then
for t:=1 to 4 do
begin
for k:=1 to 4 do
write(a[t,k],' ');
writeln;
end;
writeln;
exit;
end;
x1:=x;
y1:=y+1;
if y1=5 then
begin
y1:=1;
inc(x1);
end;
if a[x,y]=1 then sou(x1,y1)
else
for t:=2 to 16 do
if b[t]=0 then
begin
a[x,y]:=t;
b[t]:=1;
if (x=1)and(y=1)or(x=4)and(y=4)or(x=1)and(y=4)or(x=4)and(y=1) then
j1:=j1+t;
if ((x=1)or(x=2))and((y=1)or(y=2)) then j2[1]:=j2[1]+t
else if((x=1)or(x=2))and((y=3)or(y=4)) then j2[2]:=j2[2]+t
else if((x=3)or(x=4))and((y=1)or(y=2)) then j2[3]:=j2[3]+t
else j2[4]:=j2[4]+t;
if ((x=2)or(x=3))and((y=2)or(y=3)) then j3:=j3+t;
j4[x]:=j4[x]+t;
j5[y]:=j5[y]+t;
if x=y then j6:=j6+t;
if x+y=5 then j7:=j7+t;
if (j1>34)or(j2[1]>34)or(j2[2]>34)or(j2[3]>34)or(j2[4]>34)
or (j3>34)or(j4[1]>34)or(j4[2]>34)or(j4[3]>34)or(j4[4]>34)
or (j6>34)or(j7>34)or(j5[1]>34)or(j5[2]>34)or(j5[3]>34)or(j5[4]>34) then
begin
a[x,y]:=0;
b[t]:=0;
if (x=1)and(y=1)or(x=4)and(y=4)or(x=1)and(y=4)or(x=4)and(y=1) then
j1:=j1-t;
if ((x=1)or(x=2))and((y=1)or(y=2)) then j2[1]:=j2[1]-t
else if((x=1)or(x=2))and((y=3)or(y=4)) then j2[2]:=j2[2]-t
else if((x=3)or(x=4))and((y=1)or(y=2)) then j2[3]:=j2[3]-t
else j2[4]:=j2[4]-t;
if ((x=2)or(x=3))and((y=2)or(y=3)) then j3:=j3-t;
j4[x]:=j4[x]-t;
j5[y]:=j5[y]-t;
if x=y then j6:=j6-t;
if x+y=5 then j7:=j7-t;
exit;
end;
sou(x1,y1);
a[x,y]:=0;
b[t]:=0;
if (x=1)and(y=1)or(x=4)and(y=4)or(x=1)and(y=4)or(x=4)and(y=1) then
j1:=j1-t;
if ((x=1)or(x=2))and((y=1)or(y=2)) then j2[1]:=j2[1]-t
else if((x=1)or(x=2))and((y=3)or(y=4)) then j2[2]:=j2[2]-t
else if((x=3)or(x=4))and((y=1)or(y=2)) then j2[3]:=j2[3]-t
else j2[4]:=j2[4]-t;
if ((x=2)or(x=3))and((y=2)or(y=3)) then j3:=j3-t;
j4[x]:=j4[x]-t;
j5[y]:=j5[y]-t;
if x=y then j6:=j6-t;
if x+y=5 then j7:=j7-t;
end;
end;
begin
assign(input,'magic.in');
reset(input);
assign(output,'magic.out');
rewrite(output);
readln(m,n);
a[m,n]:=1;
x:=m;
y:=n;
t:=1;
if (x=1)and(y=1)or(x=4)and(y=4)or(x=1)and(y=4)or(x=4)and(y=1) then
j1:=j1+t;
if ((x=1)or(x=2))and((y=1)or(y=2)) then j2[1]:=j2[1]+t
else if((x=1)or(x=2))and((y=3)or(y=4)) then j2[2]:=j2[2]+t
else if((x=3)or(x=4))and((y=1)or(y=2)) then j2[3]:=j2[3]+t
else j2[4]:=j2[4]+t;
if ((x=2)or(x=3))and((y=2)or(y=3)) then j3:=j3+t;
j4[x]:=j4[x]+t;
j5[y]:=j5[y]+t;
if x=y then j6:=j6+t;
if x+y=5 then j7:=j7+t;
b[1]:=1;
sou(1,1);
close(output);
end.