比赛 NOIP_4 评测结果 AAAWAWAAAA
题目名称 算24点 最终得分 80
用户昵称 zxc111 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-09-19 21:12:17
显示代码纯文本
program ooo;
var
a,b,d:array[1..4] of longint;
c:array[1..4] of boolean;
i,j,k,l,sum,m:longint;
f:boolean;
t:text;
procedure oooo(kk:longint);

begin
case kk of
1:begin
if m>d[i] then
writeln(t,m,'+',d[i],'=',m+d[i]) else
writeln(t,d[i],'+',m,'=',m+d[i]);
m:=m+d[i];end;
2:begin
if m>d[i] then
writeln(t,m,'-',d[i],'=',m-d[i]) else
writeln(t,d[i],'-',m,'=',m-d[i]);
m:=m-d[i];end;
3:begin
if m>d[i] then
writeln(t,m,'*',d[i],'=',m*d[i]) else
writeln(t,d[i],'*',m,'=',m*d[i]);
m:=m*d[i];end;
4:begin
if m>d[i] then
writeln(t,m,'/',d[i],'=',m div d[i]) else
writeln(t,d[i],'/',m,'=',m div d[i]);
m:=m div d[i];
end;
end;
end;

procedure oo(p,q:longint);
var
i,j,k:longint;
begin
j:=sum;
if q=4 then
 if p=24 then begin f:=true;exit;end else exit;
for i:=1 to 4 do
if c[i]=false then
 begin
  c[i]:=true;
  oo(p+a[i],q+1);b[q]:=1;d[q+1]:=a[i];if f=true then exit;
  oo(p-a[i],q+1);b[q]:=2;if f=true then exit;
  oo(p*a[i],q+1);b[q]:=3;if f=true then exit;
  if (p div a[i]>=1)and(p mod a[i]=0)and(p>a[i]) then begin
  oo(p div a[i],q+1);b[q]:=4;end;if f=true then exit;
  c[i]:=false;
 end;
end;

begin
assign(t,'point24.in');
reset(t);
read(t,a[1],a[2],a[3],a[4]);
close(t);
for i:=1 to 4 do
 begin
  fillchar(c,sizeof(c),false);
  c[i]:=true;
  d[1]:=a[i];
  oo(a[i],1);
  if f=true then break;
 end;
i:=2;
m:=d[1];
assign(t,'point24.out');
rewrite(t);
if f=true then
 begin
oooo(b[1]);
i:=3;
oooo(b[2]);
i:=4;
oooo(b[3]);
end else write(t,'No answer!');
close(t);
end.