讨论 / 求助
曹操 2008-03-16 00:46:00
点我顶贴 收藏 删除
var

a:array[1..4,1..4] of real;

s:string;

x,y,z,d,i,j,k,l,tot:integer;

procedure done(wei:integer);

var

i1,j1,k1,l1:integer;

begin

if (wei=3) then

begin

x:=0;y:=0;z:=0;d:=0;

if a[3,1]+a[3,2]=24 then x:=1;

if (abs(a[3,1]-a[3,2])=24) then y:=1;

if a[3,1]*a[3,2]=24 then z:=1;

if ((a[3,2]<>0)and(a[3,1]/a[3,2]=24))or((a[3,1]<>0)and(a[3,2]/a[3,1]=24))

then d:=1;

if x+y+z+d<>0 then begin

write(yes);

halt;

end;

exit;

end;

for i:=1 to 5-wei do

for j:=1 to 5-wei do

if j<>i then

begin

tot:=0;

for l:=1 to 5-wei do

if (l<>i)and(l<>j) then begin

inc(tot);

a[tot,wei+1]:=a[l,wei];

end;

for k:=1 to 4 do

case k of

1:begin

a[tot+1,wei+1]:=a[i,wei]+a[j,wei];

done(wei+1);

end;

2:begin

a[tot+1,wei+1]:=a[i,wei]-a[j,wei];

done(wei+1);

end;

3:begin

a[tot+1,wei+1]:=a[i,wei]*a[j,wei];

done(wei+1);

end;

4:if a[j,wei]<>0 then

begin

a[tot+1,wei+1]:=a[i,wei]/a[j,wei];

done(wei+1);

end;

end;

end;

end;

begin

read(s);

tot:=0;

for i:=1 to length(s) do

case s[i] of

2..9:begin

inc(tot);

a[tot,1]:=ord(s[i])-ord(0);

end;

A:begin inc(tot); a[tot,1]:=1; end;

J:begin inc(tot);a[tot,1]:=11; end;

K:begin inc(tot);a[tot,1]:=13; end;

Q:begin inc(tot);a[tot,1]:=12; end;

1:begin inc(tot);a[tot,1]:=10; end;

end;

for i:=1 to 4 do

begin

for j:=1 to 4 do

if i<>j then

begin

tot:=1;

for l:=1 to 4 do

if (l<>i)and(l<>j) then begin

inc(tot);

a[tot,2]:=a[l,1];

end;

for k:=1 to 4 do

case k of

1:begin

a[1,2]:=a[i,1]+a[j,1];

done(2);

end;

2:begin

a[1,2]:=a[i,1]-a[j,1];

done(2);

end;

3:begin

a[1,2]:=a[i,1]*a[j,1];

done(2);

end;

4:begin

if a[j,1]<>0 then begin

a[1,2]:=a[i,1]/a[j,1];

done(2);

end;

end;

end;

end;

end;

write(no);

end.

求平

#1 whitegene@2008-03-16 00:46:00
回复 删除
好像不用这么麻烦吧..直接暴力搜就可以了
查看更多回复
提交回复