记录编号 15385 评测结果 AAAAAA
题目名称 [POI 1997] 阿里巴巴 最终得分 100
用户昵称 Gravatar王瑞祥K 是否通过 通过
代码语言 Pascal 运行时间 0.026 s
提交时间 2009-11-12 17:21:10 内存使用 1.19 MiB
显示代码纯文本
program ali(input,output);
var
 hash:array[0..100,0..100,0..100]of boolean;
 queue:array[1..10000,1..3] of integer;
 step:array[1..10000]of longint;
 rule:array[1..10,1..6]of integer;
 ed:array[1..3]of integer;
 i,d,r:longint;
function check(k:longint):boolean;
begin
 if (queue[k,1]>=ed[1])and(queue[k,2]>=ed[2])and(queue[k,3]>=ed[3])then exit(true) else exit(false);
end;
procedure ini;
var i,j:integer;
begin
 readln(queue[1,1],queue[1,2],queue[1,3]);
 readln(ed[1],ed[2],ed[3]);
 readln(r);
 for i:=1 to r do
  for j:=1 to 6 do
   read(rule[i,j]);
end;
procedure bfs;
var head,tail,i:longint; a,b,c:integer;
begin
 fillchar(hash,sizeof(hash),true);
 head:=1; tail:=1; step[head]:=0;
 hash[queue[1,1],queue[1,2],queue[1,3]]:=false;
 if check(tail) then begin writeln(0); exit;end;
 while head<=tail do begin
  for i:=1 to r do
   if (queue[head,1]>=rule[i,1])and(queue[head,2]>=rule[i,2])and(queue[head,3]>=rule[i,3])then begin
    a:=queue[head,1]-rule[i,1]+rule[i,4];
    b:=queue[head,2]-rule[i,2]+rule[i,5];
    c:=queue[head,3]-rule[i,3]+rule[i,6];
    if (a<=100)and(b<=100)and(c<=100)then
    if hash[a,b,c] then begin
     inc(tail);
     queue[tail,1]:=a;
     queue[tail,2]:=b;
     queue[tail,3]:=c;
     step[tail]:=step[head]+1;
     hash[a,b,c]:=false;
     if check(tail) then begin writeln(step[tail]);exit; end;
    end;
   end;
  head:=head+1;
 end;
 writeln('NIE');
 exit;
end;
begin
 assign(input,'ali.in');assign(output,'ali.out');
 reset(input);rewrite(output);
 readln(d);
 for i:=1 to d do begin
  ini;
  bfs;
 end;
 close(input);close(output);
end.