讨论 / 怎么加括号啊
tzh 2010-08-16 05:55:00
点我顶贴 收藏 删除
我的程序

program t74;

var

b,c,d:integer;

a:array[1..4]of integer;

s,t:char;

procedure sou(o,p:integer);

var

i,j,k:integer;

begin

if o=24 then begin write('yes');halt;end;

if p=5 then exit;

sou(o+a[p],p+1);

sou(o-a[p],p+1);

sou(o*a[p],p+1);

if (a[p]<>0)and(o mod a[p]=0) then sou(o div a[p],p+1);

end;

begin

for b:=1 to 4 do

begin

read(s); if b<>4 then read(t);

if s='1' then begin read(t);a[b]:=10 end else

case s of

'A':a[b]:=1;

'2':a[b]:=2;

'3':a[b]:=3;

'4':a[b]:=4;

'5':a[b]:=5;

'6':a[b]:=6;

'7':a[b]:=7;

'8':a[b]:=8;

'9':a[b]:=9;

'J':a[b]:=11;

'Q':a[b]:=12;

'K':a[b]:=13;

end;

end;

c:=0; d:=1;

sou(c,d);

write('no');

end.

#1 abccbazj@2010-08-10 19:46:00
回复 删除
深搜的时候再加两个dfs

sou(a[p]-o,p+1);

if (o<>0) then sou(o / a[p],p+1);

#2 abccbazj@2010-08-11 14:57:00
回复 删除
读数的时候还要考虑读入的不是10而是1的情况
#3 abccbazj@2010-08-11 14:58:00
回复 删除
读数的时候还要考虑读入的不是10而是1的情况
#4 tzh@2010-08-16 05:55:00
回复 删除
分更低了

照你说得改了

分更低了

就剩50了

program t74;

var

b,c,d:integer;

a:array[1..4]of integer;

s,t:char;

procedure sou(o,p:integer);

var

i,j,k:integer;

begin

if o=24 then begin write('yes');halt;end;

if p=5 then exit;

sou(a[p]-o,p+1);

sou(o+a[p],p+1);

sou(o-a[p],p+1);

sou(o*a[p],p+1);

if (o<>0)and(o mod a[p]=0) then sou(o div a[p],p+1);

end;

begin

for b:=1 to 4 do

begin

read(s); if b<>4 then read(t);

if s='1' then begin read(t);a[b]:=10 end else

case s of

'A':a[b]:=1;

'2':a[b]:=2;

'3':a[b]:=3;

'4':a[b]:=4;

'5':a[b]:=5;

'6':a[b]:=6;

'7':a[b]:=7;

'8':a[b]:=8;

'9':a[b]:=9;

'J':a[b]:=11;

'Q':a[b]:=12;

'K':a[b]:=13;

end;

end;

c:=0; d:=1;

sou(c,d);

write('no');

end.

查看更多回复
提交回复