状态: Unaccepted
测评机: Xeond[6]
得分: 80分
提交日期: 2013-7-8 16:57:00
有效耗时: 1344毫秒
测试结果1: 通过本测试点|有效耗时172ms
测试结果2: 测试结果错误.错误结果为:no 正确结果应为:yes
测试结果3: 通过本测试点|有效耗时156ms
测试结果4: 通过本测试点|有效耗时172ms
测试结果5: 测试结果错误.错误结果为:no 正确结果应为:yes
测试结果6: 通过本测试点|有效耗时172ms
测试结果7: 通过本测试点|有效耗时172ms
测试结果8: 通过本测试点|有效耗时156ms
测试结果9: 通过本测试点|有效耗时172ms
测试结果10: 通过本测试点|有效耗时172ms
晕死我了,搜半天都没AC,哪里想错了?
program ex_74;
var a:array[1..4]of real;{存4个数字}
b:array[1..24,1..4]of integer=
((1,2,3,4),(1,2,4,3),(1,3,2,4),(1,3,4,2),(1,4,2,3),(1,4,3,2),
(2,1,3,4),(2,1,4,3),(2,3,1,4),(2,3,4,1),(2,4,1,3),(2,4,3,1),
(3,2,1,4),(3,2,4,1),(3,1,2,4),(3,1,4,2),(3,4,1,3),(3,4,1,2),
(4,2,3,1),(4,2,1,3),(4,3,2,1),(4,3,1,2),(4,1,2,3),(4,1,3,2));{存24种计算顺序,虽然没简化,但是时间不长}
i,j:integer;
c:char;
procedure dfs(ans:real;i:integer);{ans是当前计算结果,i是当前计算到第几个数字}
begin
if (abs(ans-24)<=0.000001)and(i=4) then
begin writeln('yes');halt;end;
if i=4 then exit;
inc(i);
dfs(ans+a[b[j,i]],i);
dfs(ans-a[b[j,i]],i);
dfs(ans*a[b[j,i]],i);
if a[i]<>0 then dfs(ans/a[b[j,i]],i);
end;
begin
for i:=1to 4 do
begin
read(c);
case c of
'1':a[i]:=10;{读到1就是10}
'2','3','4','5','6','7','8','9':a[i]:=ord(c)-48;
'A':a[i]:=1;
'J':a[i]:=11;
'Q':a[i]:=12;
'K':a[i]:=13;
end;
if i=4 then break;
read(c);{读空格}
if a[i]=10 then read(c);{如果出现10,因为少读个0,所以,多读一位}
end;
for j:=1to 24 do
begin
i:=1;
dfs(a[b[j,i]],i);
end;{暴搜24种排列下的结果}
writeln('no');
end.
注释很详细了吧。。。哪位大神帮帮我啊。我有点晕了