算法:枚举
分析:就是给定了三种饲料的比例然后配出需要的饲料就行了,注意给出的比例中包括了0,所以还要特判一下0这种情况。
{
ID:1011mashuo
PROG:ratios
LANG:PASCAL
}
program ratios;
var
a,b,c,a1,a2,a3,b1,b2,b3,c1,c2,c3,x1,x2,x3,x4,min:longint;
procedure init;
begin
min:=maxlongint;
readln(a,b,c);
readln(a1,b1,c1);
readln(a2,b2,c2);
readln(a3,b3,c3);
end;
function check(x,y:longint):boolean;
begin
if (x=0) and (y=0) then exit(true);{如果两项都是0,即需要的饲料也是0,选定的饲料也是0就是成立的。}
if (x=0) or (y=0) then exit(false);{如果只有其中一项是0,即如果不需要这种饲料但是买了就是白费,如果需要的话但是没买也不行。}
if x mod y=0 then exit(true) else exit(false);{如果是整倍数才能成立。}
end;
function cal(x,y:longint):longint;
begin
if y=0 then exit(0);{计算,不排除除数是0的情况所以需要特判。}
exit(x div y);
end;
procedure main;
var
i,j,k,t1,t2,t3,x11,x12,x13:longint;
begin
for i:=0 to 99 do
begin
for j:=0 to 99 do
begin
for k:=0 to 99 do
begin
t1:=i*a1+j*a2+k*a3;
t2:=i*b1+j*b2+k*b3;
t3:=i*c1+j*c2+k*c3;
if (check(t1,a)) and (check(t2,b)) and (check(t3,c)) then
begin
x11:=cal(t1,a);
x12:=cal(t2,b);
x13:=cal(t3,c);
if ((x11=x12) and (x13=0)) or ((x11=x13) and (x12=0)) or ((x12=x13) and (x11=0)) or ((x11=x12) and (x12=x13) and (x11=x13)) then{把4种情况都分析清楚了,可能只有1种饲料不用买,也可能都需要买,这里只要判断相等就行。}
begin
write(i,' ',j,' ',k,' ');{因为我们按序找的,所以一定是最小的。}
if x11<>0 then writeln(x11) else if x12<>0 then writeln(x12) else if x13<>0 then writeln(x13);
close(input);
close(output);
halt;
end;
end;
end;
end;
end;
end;
begin
assign(input,'ratios.in'); reset(input);
assign(output,'ratios.out'); rewrite(output);
init;
main;
writeln('NONE');
close(input); close(output);
end.