比赛 20091112练习 评测结果 AWWWWW
题目名称 阿里巴巴 最终得分 16
用户昵称 ZhouZn1 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2009-11-12 11:45:09
显示代码纯文本
program ali;
type
        rec=record
        zz,ss,mm:longint;
        dep:integer;
        end;
        rec1=record
        z1,s1,m1,z2,s2,m2:integer;
        end;
var
        i,j,d,zp,sp,mp,z,s,m,head,tail:longint;
        r:byte;
        list:array[1..1000000]of rec;
        rr:array[1..10]of rec1;
        v:array[0..100,0..100,0..100]of boolean;
procedure init;
begin
        readln(zp,sp,mp);
        readln(z,s,m);
        readln(r);
        for i:=1 to r do
        with rr[i] do
        readln(z1,s1,m1,z2,s2,m2);
        fillchar(v,sizeof(v),0);
end;
function check(ii:integer;var zz1,ss1,mm1:longint):boolean;
begin
        if zz1-rr[ii].z1<0 then exit(false);
        if ss1-rr[ii].s1<0 then exit(false);
        if mm1-rr[ii].m1<0 then exit(false);
        zz1:=zz1-rr[ii].z1;
        ss1:=ss1-rr[ii].s1;
        mm1:=mm1-rr[ii].m1;
        exit(true);
end;
procedure main;
var
        i:integer;
        zn,sn,mn,zt,st,mt:longint;
begin
        head:=0;
        tail:=1;
        with list[1] do
        begin
        zz:=zp;
        ss:=sp;
        mm:=mp;
        dep:=0;
        end;
        v[zp,sp,mp]:=true;
        repeat
                inc(head);
                if list[head].dep>20 then break;
                for i:=1 to r do
                begin
                zn:=list[head].zz;
                sn:=list[head].ss;
                mn:=list[head].mm;
                if check(i,zn,sn,mn) then
                begin
                        zt:=zn+rr[i].z2;
                        st:=sn+rr[i].s2;
                        mt:=mn+rr[i].m2;
                        if (zt>=z)and(st>=s)and(mt>=m) then
                        begin
                        writeln(list[head].dep+1);
                        exit;
                        end; //ans
                        if (not(v[zt,st,mt]))and(zt<=100)and(st<=100)and(mt<=100) then
                        begin
                                inc(tail);
                                with list[tail] do
                                begin
                                        zz:=zt;
                                        ss:=st;
                                        mm:=mt;
                                        dep:=list[head].dep+1;
                                end;
                                v[zt,st,mt]:=true;
                        end;
                end;
                end;
        until head>tail;
        writeln('NIE');
end;
begin
        assign(input,'ali.in');
        reset(input);
        assign(output,'ali.out');
        rewrite(output);
        readln(d);
        while d>0 do
        begin
        dec(d);
        init;
        main;
        end;
        close(input);
        close(output);
end.