记录编号 |
12260 |
评测结果 |
WAAAAWAAAA |
题目名称 |
算24点 |
最终得分 |
80 |
用户昵称 |
Achilles |
是否通过 |
未通过 |
代码语言 |
Pascal |
运行时间 |
0.002 s |
提交时间 |
2009-09-08 17:33:28 |
内存使用 |
0.11 MiB |
显示代码纯文本
program point24;
type arr=array [1..4] of integer;
var i,result,n,len:integer;
d:arr;
r:array [1..3,1..4] of integer;
procedure print;
var i,j:integer;
begin
assign(output,'point24.out');
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 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(input,'point24.in');
reset(input);
for i:=1 to 4 do read(input,d[i]);
close(input);
try(4,d);
assign(output,'point24.out');
rewrite(output);
writeln('No answer!');
close(output);
end.