比赛 NOIP_4 评测结果 WAAAAWAAAA
题目名称 算24点 最终得分 80
用户昵称 NOIer 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-09-19 22:04:15
显示代码纯文本
//Problem : Noip;
//Author  : CaiXinXiao;
//Way     : Search;
//Date    : 09-19;

Program Point24;
Const
  Inf   = 'point24.in';
  Ouf   = 'point24.out';
Type
  Arr   = Array[1..4] of Longint;
Var
    D     : Arr;
    r     : Array [1..3,1..4] of Longint;
    i,n   : Longint;
    result: Longint;
    Len   : Longint;


Procedure Print;
  Var
    i,j:integer;
  Begin
    Assign(output,Ouf); rewrite(output);
    For i:=1 to 3 do
    Begin
      For j:=1 to 3 do
        if j<>2 then write(r[i,j])
          Else
            Case R[i,j] of
                  1:write('+');
                  2:write('-');
                  3:write('*');
                  4:write('/')
            End;
          writeln('=',r[i,4])
    End;
  close(output);
end;

Procedure Search(k:Longint;d:Arr);
  Var
    A,B,i,j,l,t:Longint;
    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];
                  Search(k-1,e)
                 End
           End
          End
       End;
    End;

Begin
  Assign(input,Inf);  reset(input);
  For i:=1 to 4 do Read(d[i]);
  close(input);
  Search(4,d);
  assign(output,Ouf); rewrite(output);
  writeln('No answer!');
  Close(output);
End.