比赛 |
20091112练习 |
评测结果 |
C |
题目名称 |
平衡的阵容 |
最终得分 |
0 |
用户昵称 |
bing |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2009-11-12 11:59:51 |
显示代码纯文本
program bing;
var
f1,f2:text;
d,r:integer;
a0,a1:integer;
a:array[1..10,0..1] of integer;
procedure init;
begin
assign(f1,'ali.in');reset(F1);
assign(f2,'ali.out');rewrite(f2);
readln(f1,d);
end;
function pd(x,y:integer):boolean;
var
i:integer;
begin
pd:=true;
for i:=1 to 3 do
begin
if (x mod 10)<(y mod 10) then exit(false)
else
begin
x:=x div 10;y:=y div 10;
end;
end;
end;
function cl(x,y,z:integer):integer;
var
i,k:integer;
begin
cl:=0;
k:=1;
for i:=1 to 3 do
begin
cl:=cl+k*((x mod 10)-(y mod 10)+(z mod 10));
x:=x div 10;y:=y div 10;z:=z div 10;
k:=k*10;
end;
end;
procedure nb;
var
h,t,i,m:integer;
q:array[1..1000] of integer;
p:array[1..1000] of integer;
b:array[0..444] of boolean;
begin
fillchar(b,sizeof(b),true);
h:=1;t:=1;
q[h]:=a0;
p[h]:=0;
b[a0]:=false;
repeat
for i:=1 to r do
if pd(a[i,0],q[h]) then
begin
m:=cl(q[h],a[i,0],a[i,1]);
if b[m] then
begin
inc(t);
q[t]:=m;
p[t]:=p[h]+1;
if q[t]=a1 then begin writeln(f2,p[t]);exit;end;
b[m]:=false;
end;
end;
inc(h);
until h>t;
if h>t then writeln(f2,'NIE');
end;
procedure main;
var
i,j:integer;
x1,x2,x3:0..4;
begin
for i:=1 to d do
begin
readln(f1,x1,x2,x3);
a0:=x1*100+x2*10+x3;
readln(f1,x1,x2,x3);
a1:=x1*100+x2*10+x3;
readln(f1,r);
for j:=1 to r do
begin
read(f1,x1,x2,x3);
a[i,0]:=x1*100+x2*10+x3;
readln(f1,x1,x2,x3);
a[i,1]:=x1*100+x2*10+x3;
end;
nb;
end;
end;
begin
init;
main;
close(f1);close(f2);
end.