记录编号 |
79494 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[POJ1657] 棋盘上的距离 |
最终得分 |
100 |
用户昵称 |
翟佳麒是我孙子 |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
0.001 s |
提交时间 |
2013-11-05 20:39:36 |
内存使用 |
0.17 MiB |
显示代码纯文本
function max1(a,b:integer):integer;
begin
if a>b then max1:=a
else max1:=b;
end;
function min1(a,b:integer):integer;
begin
if a<b then min1:=a
else min1:=b;
end;
var
fx,lx,fy,ly,q,t:integer;
st:string;
a:array[-1..7,-1..7]of integer;
b:boolean;
procedure change;
var
o,v,b:integer;
begin
v:=abs(lx-fx);
b:=abs(ly-fy);
fx:=0;
fy:=0;
lx:=v;
ly:=b;
end;
function king:integer;
var
l,px,py,k:integer;
begin
king:=0;
if lx=fx then begin
king:=ly-fy;
exit;
end;
if ly=fy then begin
king:=lx-fx;
exit;
end;
l:=min1(lx,ly);
k:=max1(lx,ly);
king:=l;
px:=l;
py:=l;
if px=lx then king:=king+ly-py
else king:=king+lx-px;
end;
function queen:integer;
begin
queen:=0;
if lx=fx then begin
queen:=1;
exit;
end;
if ly=fy then begin
queen:=1;
exit;
end;
if ly-lx=0 then begin
queen:=1;
exit;
end;
queen:=2;
end;
function car:integer;
begin
car:=0;
if lx<>fx then car:=car+1;
if ly<>fy then car:=car+1;
end;
function elephant:integer;
var
x,y:integer;
begin
a[-1,0]:=1;
a[0,-1]:=1;
for x:=0 to 7 do
for y:=0 to 7 do if (a[x-1,y]=1)or(a[x,y-1]=1) then a[x,y]:=2
else a[x,y]:=1;
if a[lx,ly]=a[fx,fy] then begin
if lx-ly=0 then begin
elephant:=1;
exit;
end;
elephant:=2;
exit;
end;
elephant:=0;
end;
var
a1,a2,a3,a4:char;
qw,qe,qr,qt:integer;
begin
assign(input,'poj_1657.in');
reset(input);
assign(output,'poj_1657.out');
rewrite(output);
b:=false;
fx:=0;
lx:=0;
fy:=0;
ly:=0;
q:=0;
t:=0;
st:='';
readln(t);
for q:=1 to t do begin
readln(st);
a1:=st[1];
a2:=st[4];
a3:=st[2];
a4:=st[5];
fx:=ord(a1)-97;
lx:=ord(a2)-97;
val(a3,fy);
val(a4,ly);
if (fx=lx)and(ly=fy) then begin
write(0,' ',0,' ',0,' ',0);
writeln;
continue;
end;
change;
qw:=king;
qe:=queen;
qr:=car;
qt:=elephant;
write(qw,' ',qe,' ',qr,' ');
if (king<>0)and(qt=0) then write('Inf')
else write(qt);
writeln;
end;
close(input);
close(output);
end.