代码暂存

const dx:array[0..3]of longint=(0,1,0,-1);
dy:array[0..3]of longint=(1,0,-1,0);
var x,y,d:array[1..2]of longint;
n,t,i,j,k:longint;
a,b:array[-11..1011,-11..1011]of boolean;
function way1(x:longint):longint;
begin
case x of
0:exit(1);
1:exit(2);
2:exit(3);
3:exit(0);
end;
end;
function way2(x:longint):longint;
begin
case x of
0:exit(3);
1:exit(0);
2:exit(1);
3:exit(2);
end;
end;
procedure dfs;
var b1,b2:boolean;
h,l:longint;
begin
h:=0; l:=0;
a[x[1],y[1]]:=false; b[x[2],y[2]]:=false;
b1:=true; b2:=true;
while (x[1]<>x[2])or(y[1]<>y[2]) do
begin
if b1 then
begin
l:=x[1]+dx[d[1]];h:=y[1]+dy[d[1]];
if not a[l,h] then
begin
d[1]:=way1(d[1]);
l:=x[1]+dx[d[1]]; h:=y[1]+dy[d[1]];
if not a[l,h] then b1:=false;
end;
if b1 then begin x[1]:=l; y[1]:=h; a[l,h]:=false; end;
end;
if b2 then
begin
l:=x[2]+dx[d[2]];h:=y[2]+dy[d[2]];
if not b[l,h] then
begin
d[2]:=way2(d[2]);
l:=x[2]+dx[d[2]]; h:=y[2]+dy[d[2]];
if not b[l,h] then b2:=false;
end;
if b2 then begin x[2]:=l; y[2]:=h; b[l,h]:=false end;
end;
if not b1 and not b2 then break;
end;
if (x[1]=x[2])and(y[1]=y[2]) then writeln(x[1],’ ‘,y[1]) else writeln(-1);
end;
begin
{assign(input,’fight.in’);
assign(output,’fight.out’);
reset(input);
rewrite(output); }
read(t);
for i:=1 to t do
begin
read(n,x[1],y[1],d[1],x[2],y[2],d[2]);
for j:=0 to n-1 do for k:=0 to n-1 do
begin
a[j,k]:=true;
b[j,k]:=true;
end;
dfs;
end;
close(input);
close(output);
end.

你可能感兴趣的:(代码暂存)