比赛 |
20091112练习 |
评测结果 |
EAEEEE |
题目名称 |
阿里巴巴 |
最终得分 |
16 |
用户昵称 |
EnAsn |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2009-11-12 11:58:20 |
显示代码纯文本
program ex;
const
h:array[1..3]of integer=(100,10,1);
type
zz=array[0..3]of integer;
ss=array[1..1000]of boolean;
sz=array[1..10,1..2]of zz;
zs=array[1..1000000]of zz;
var
flag:ss;
f:sz;
ans1:zs;
ans2:zz;
d,n,i:integer;
function search:boolean;
var
head,tail:integer;
fla:boolean;
i,j,x:integer;
begin
search:=false;
head:=1;tail:=1;
i:=1;
flag[ans1[1][1]*h[1]+ans1[2][2]*h[2]+ans1[3][3]*h[3]]:=false;
while head<=tail do
begin
for i:=1 to n do
if (f[i,1][1]<=ans1[head][1])and(f[i,1][2]<=ans1[head][2])and(f[i,1][3]<=ans1[head][3]) then
begin
inc(tail);x:=0;
ans1[tail][0]:=ans1[head][0]+1;
if ans1[tail][0]>100 then exit(false);
for j:=1 to 3 do
begin
ans1[tail][j]:=ans1[head][j]-f[i,1][j]+f[i,2][j];
x:=x+ans1[tail][j]*h[j];
end;
if flag[x] then
begin
fla:=true;
flag[x]:=false;
for j:=1 to 3 do
if ans2[j]>ans1[tail][j] then fla:=false;
if fla then
begin
writeln(ans1[tail][0]);
exit(true);
end;
end;
end;
inc(head);
end;
end;
procedure fuck;
var
i,j:integer;
x:integer;
head1,tail1,head2,tail2:integer;
begin
for i:=1 to 1000 do flag[i]:=true;
fillchar(ans1,sizeof(ans1),0);
fillchar(ans2,sizeof(ans2),0);
fillchar(f,sizeof(f),0);
for i:=1 to 3 do
begin
read(x);
ans1[1][i]:=x;
end;
readln;
for i:=1 to 3 do read(ans2[i]);
readln;
readln(n);
for i:=1 to n do
begin
readln(f[i,1][1],f[i,1][2],f[i,1][3],f[i,2][1],f[i,2][2],f[i,2][3]);
end;
if not search then writeln('NIE');
end;
begin
assign(input,'ali.in');
assign(output,'ali.out');
reset(input);
rewrite(output);
readln(d);
for i:=1 to d do fuck;
close(input);
close(output);
end.