比赛 20100914 评测结果 WAAAAWAAAA
题目名称 算24点 最终得分 80
用户昵称 ZHZH 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-09-14 21:49:35
显示代码纯文本
program twentyfourpoint;
type arr=array [1..4] of integer;
var i,result,n,len:integer;
    d:arr;
    r:array [1..3,1..4] of integer;
    f:text;
procedure print;
var i,j:integer;
begin
  assign(f,'point24.out');
  rewrite(f);
  for i:=1 to 3 do
  begin
      for j:=1 to 3 do
        if j<>2 then write(f,r[i,j])
          else case r[i,j] of
                  1:write(f,'+');
                  2:write(f,'-');
                  3:write(f,'*');
                  4:write(f,'/')
                end;
       writeln(f,'=',r[i,4])
    end;
  close(f);
end;
procedure try(k:integer;d:arr);
var a,b,i,j,l,t:integer;
    e:arr;
begin
  if k=1 then if d[1]=24 then begin print;halt end else
     else
     begin
       for i:=1 to k-1 do
        for j:=i+1 to k do
         begin
           a:=d[i]; b:=d[j];
           if a<b then begin t:=a;a:=b;b:=t end;
           t:=0;
           for l:=1 to k do if (l<>i) and (l<>j) then begin t:=t+1;e[t]:=d[l] end;
           r[5-k,1]:=a;
           r[5-k,3]:=b;
           r[5-k,4]:=-1;
           for l:=1 to 4 do
            begin
             case l of
               1:r[5-k,4]:=a+b;
               2:r[5-k,4]:=a-b;
               3:r[5-k,4]:=a*b;
               4:if b<>0  then if a mod b=0 then r[5-k,4]:=a div b
             end;
            r[5-k,2]:=l;
            if r[5-k,4]<>-1 then
                 begin
                  e[t+1]:=r[5-k,4];
                  try(k-1,e)
                 end
           end
        end
     end;
end;
begin
  assign(f,'point24.in');
  reset(f);
  for i:=1 to 4 do read(f,d[i]);
  close(f);
  try(4,d);
  assign(f,'point24.out');
  rewrite(f);
  writeln(f,'No answer!');
  close(f);
end.