比赛 20091112练习 评测结果 AATAAA
题目名称 阿里巴巴 最终得分 83
用户昵称 打不死的羊 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2009-11-12 11:09:47
显示代码纯文本
program ali;
type
fxz1=record z,s,m:shortint;end;
fxz2=array[0..1000000] of fxz1;
var
f1,f2:text;
mu:fxz1;
ls,g1,g2:fxz2;
i,j,n,k,ans,ans2,t,w,ww,nn:longint;

      procedure chu(q:fxz1);
      var
      flag:boolean;
      i,j:longint;
      qq:fxz1;
      begin for i:=1 to n do
            if (q.z>=g1[i].z)and(q.s>=g1[i].s)and(q.m>=g1[i].m) then
                            begin qq.z:=q.z-g1[i].z+g2[i].z;
                                  qq.s:=q.s-g1[i].s+g2[i].s;
                                  qq.m:=q.m-g1[i].m+g2[i].m;

                                  flag:=true;
                                  for j:=0 to ww do
                                  if (qq.z=ls[j].z)and(qq.s=ls[j].s)and(qq.m=ls[j].m) then
                                   begin flag:=false;
                                         break;
                                   end;
                                   if flag then begin inc(ww);ls[ww]:=qq;end;
                             end;
      end;





begin assign(f1,'ali.in');
      assign(f2,'ali.out');
      reset(f1);rewrite(f2);
      readln(f1,nn);
      for k:=1 to nn do
      begin fillchar(ls,sizeof(ls),0);
            with ls[0] do
            readln(f1,z,s,m);
            with mu do
            readln(f1,z,s,m);
            readln(f1,n);
            for i:=1 to n do
            readln(f1,g1[i].z,g1[i].s,g1[i].m,g2[i].z,g2[i].s,g2[i].m);
            t:=0;w:=0;ans:=0;ans2:=-1;
            repeat ww:=w;
                   for i:=t to w do
                   if(ls[i].z>=mu.z)and(ls[i].s>=mu.s)and(ls[i].m>=mu.m) then ans2:=ans
                                                           else chu(ls[i]);
                   t:=w+1;
                   w:=ww;
                   inc(ans);
            until  (t>w)or(ans2<>-1);
            if ans2=-1 then writeln(f2,'NIE')
                       else writeln(f2,ans2);
      end;
      close(f1);close(f2);
end.