比赛 |
20091112练习 |
评测结果 |
AATAAA |
题目名称 |
阿里巴巴 |
最终得分 |
83 |
用户昵称 |
rottenwood |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2009-11-12 11:09:45 |
显示代码纯文本
program ali;
type
springbrother=record
be:array[1..3] of longint;
af:array[1..3] of longint;
end;
var
r:array[1..10] of springbrother;
a:array[0..100000,1..3] of longint;
flag:boolean;
i,j,k,jp,yp,tp,m,n,ja,ya,ta,ans,rn,d,v:longint;
function pc(x,y,z,c:longint):boolean;
var i,j:longint;
begin
pc:=true;
for i:=c downto 0 do
if (a[i,1]=x)and(a[i,2]=y)and(a[i,3]=z) then begin pc:=false;break;end;
end;
procedure bfs(x,y,z:longint);
var i,j,k,head,tail,tou,wei,tol,t1,t2,t3:longint;
begin
fillchar(a,sizeof(a),0);
head:=0;tail:=0;tol:=0;
wei:=0;tou:=0;
a[0,1]:=x;a[0,2]:=y;a[0,3]:=z;
repeat
inc(tol);
tou:=head;
for k:=head to tail do
begin
for i:=1 to rn do
if (a[k,1]>=r[i].be[1])and(a[k,2]>=r[i].be[2])and(a[k,3]>=r[i].be[3]) then
begin
t1:=a[k,1]-r[i].be[1]+r[i].af[1];
t2:=a[k,2]-r[i].be[2]+r[i].af[2];
t3:=a[k,3]-r[i].be[3]+r[i].af[3];
if pc(t1,t2,t3,wei) then begin
inc(wei); a[wei,1]:=t1;a[wei,2]:=t2;a[wei,3]:=t3;
if (t1>=ja)and(t2>=ya)and(t3>=ta) then begin flag:=true;ans:=tol;exit; end;
end;
end;
end;
head:=tail+1;
tail:=wei;
until head>tail;
end;
begin
assign(input,'ali.in');reset(input);
assign(output,'ali.out');rewrite(output);
readln(d);
for v:=1 to d do
begin
readln(jp,yp,tp);
readln(ja,ya,ta);
readln(rn);
fillchar(r,sizeof(r),0);
for i:=1 to rn do
readln(r[i].be[1],r[i].be[2],r[i].be[3],r[i].af[1],r[i].af[2],r[i].af[3]);
flag:=false;
bfs(jp,yp,tp);
if flag then writeln(ans) else writeln('NIE');
end;
close(output);
end.