level 2
神de_麒麟右臂
楼主
RT
自己检查了好几遍,不知道为什么有问题。
原问题:有10升油在10升的容器中,另有7升和3升的容器各一,,要求用这三个容器倒油,使得最后在10升和7升的容器中各有5升油,问最少倒几次。
自己写的源代码:(可能比较啰嗦,入门渣渣)
var judge:boolean;
p1,p2,st,st1,st2,i,num,x,y,gg,j,aa,bb,cc,dd,ee:longint;
space,oil,:array[0..10000,0..10000] of longint;
openy,ans,bt:array[0..10000] of longint;//bt数组是容积,oil是油量(可有可无没改),space是剩余空间;
function find(stx,sty:integer):boolean;
begin
find:=true;
for aa:=1 to p2 do
if (space[x,aa]=stx)and(space[y,aa]=sty) then
begin
find:=false;
exit;
end;
end;
function small(zz,zzz:integer):integer;//判断两个数的大小;
begin
if zz<=zzz then small:=zz
else small:=zzz;
end;
procedure out;//输出;
begin
writeln(openy[p1]+1);
halt;
end;
begin
space[1,1]:=0;
space[2,1]:=7;
space[3,1]:=3;
oil[1,1]:=10;
oil[2,1]:=0;
oil[3,1]:=0;
ans[1]:=5;
ans[2]:=5;
ans[3]:=0;
for i:=1 to 3 do
bt[i]:=oil[i,1]+space[i,1];
p1:=1;
p2:=1;
fillchar(openy,sizeof(openy),0);
while p1<=p2 do
begin
for x:=1 to 3 do
for y:=1 to 3 do
begin
st:=space[x,p1];
st1:=space[y,p1];
if (st<>0) and (x<>y) and (st1<>bt[y]) then
begin
st:=st-small(st,bt[y]-st1);
st1:=st1+small(st,bt[y]-st1);
end;
if (bt[x]-st=ans[x]) and (bt[y]-st1=ans[y]) then out;
if find(st,st1) then
begin
inc(p2);
space[x,p2]:=st;
space[y,p2]:=st1;
openy[p2]:=openy[p1]+1;
end;
end;
inc(p1);
end;
end.
输出的结果永远是1,也就是说它只做了一步以内的。
尝试检查了一下,发现在第一次倒油后st和st1两个变量都变成0了。
2017年02月07日 08点02分
1
自己检查了好几遍,不知道为什么有问题。
原问题:有10升油在10升的容器中,另有7升和3升的容器各一,,要求用这三个容器倒油,使得最后在10升和7升的容器中各有5升油,问最少倒几次。
自己写的源代码:(可能比较啰嗦,入门渣渣)
var judge:boolean;
p1,p2,st,st1,st2,i,num,x,y,gg,j,aa,bb,cc,dd,ee:longint;
space,oil,:array[0..10000,0..10000] of longint;
openy,ans,bt:array[0..10000] of longint;//bt数组是容积,oil是油量(可有可无没改),space是剩余空间;
function find(stx,sty:integer):boolean;
begin
find:=true;
for aa:=1 to p2 do
if (space[x,aa]=stx)and(space[y,aa]=sty) then
begin
find:=false;
exit;
end;
end;
function small(zz,zzz:integer):integer;//判断两个数的大小;
begin
if zz<=zzz then small:=zz
else small:=zzz;
end;
procedure out;//输出;
begin
writeln(openy[p1]+1);
halt;
end;
begin
space[1,1]:=0;
space[2,1]:=7;
space[3,1]:=3;
oil[1,1]:=10;
oil[2,1]:=0;
oil[3,1]:=0;
ans[1]:=5;
ans[2]:=5;
ans[3]:=0;
for i:=1 to 3 do
bt[i]:=oil[i,1]+space[i,1];
p1:=1;
p2:=1;
fillchar(openy,sizeof(openy),0);
while p1<=p2 do
begin
for x:=1 to 3 do
for y:=1 to 3 do
begin
st:=space[x,p1];
st1:=space[y,p1];
if (st<>0) and (x<>y) and (st1<>bt[y]) then
begin
st:=st-small(st,bt[y]-st1);
st1:=st1+small(st,bt[y]-st1);
end;
if (bt[x]-st=ans[x]) and (bt[y]-st1=ans[y]) then out;
if find(st,st1) then
begin
inc(p2);
space[x,p2]:=st;
space[y,p2]:=st1;
openy[p2]:=openy[p1]+1;
end;
end;
inc(p1);
end;
end.
输出的结果永远是1,也就是说它只做了一步以内的。
尝试检查了一下,发现在第一次倒油后st和st1两个变量都变成0了。