我的想法是将四张牌上的数字错乱排列其计算顺序,然后将加减乘除可能情况列出来,如果|计算结果-24|<0.00000001 证明可以凑出24点;
但第5组总是过不了;
如下状态: Unaccepted
测评机: Xeost[5]
得分: 90分
提交日期: 2009-10-1 19:53:00
有效耗时: 530毫秒
测试结果1: 通过本测试点|有效耗时156ms
测试结果2: 通过本测试点|有效耗时47ms
测试结果3: 通过本测试点|有效耗时47ms
测试结果4: 通过本测试点|有效耗时46ms
测试结果5: 测试结果错误.错误结果为:no
正确结果应为:yes
测试结果6: 通过本测试点|有效耗时47ms
测试结果7: 通过本测试点|有效耗时47ms
测试结果8: 通过本测试点|有效耗时46ms
测试结果9: 通过本测试点|有效耗时47ms
测试结果10: 通过本测试点|有效耗时47ms
program rqnoj74;
var a:array[1..4] of real;
b:array[1..4] of integer;
s,st:string[8];
x,y,i,j,k,l,m,n:integer;
procedure change(i:string[3];var j:integer);
begin
if i=’A’ then j:=1;
if i=’J’ then j:=11;
if i=’Q’ then j:=12;
if i=’K’ then j:=13;
if j=0 then val(i,j);
end;
procedure find(n:integer);
var i:real;
begin
if n=1 then
if (abs(a[1]-24)<0.000000001) then begin writeln(’yes’);halt;end
else exit;
if a[1]=0 then exit;
i:=a[1];
a[1]:=a[1]-a[n];find(n-1);a[1]:=i;
a[1]:=a[n]-a[1];find(n-1);a[1]:=i;
a[1]:=a[1]*a[n];find(n-1);a[1]:=i;
if a[n]<>0 then
a[1]:=a[1]/a[n];find(n-1);a[1]:=i;
a[1]:=a[n]/a[1];find(n-1);a[1]:=i;
end;
begin
readln(s);
for i:=1 to 3 do begin
st:=copy(s,1,pos(’ ’,s)-1);
change(st,b[i]);
delete(s,1,pos(’ ’,s));
end;
change(s,b[4]);
for i:=1 to 4 do
for j:=1 to 4 do
begin
if i<>j then
for x:=1 to 4 do
if (x<>i)and(x<>j) then
for y:=1 to 4 do
if (y<>i)and(y<>j)and(y<>x) then begin
a[1]:=b[i];a[2]:=b[j];a[3]:=b[x];a[4]:=b[y];
find(4);
end;
end;
writeln(’no’);
end.
var i:real;
begin
if n=1 then
if (abs(a[1]-24)<0.000000001) then begin writeln(’yes’);halt;end
else exit;
if a[1]=0 then exit;
i:=a[1];
[color=red]a[1]:=a[1]+a[n];find(n-1);a[1]:=i;[/color]
a[1]:=a[1]-a[n];find(n-1);a[1]:=i;
a[1]:=a[n]-a[1];find(n-1);a[1]:=i;
a[1]:=a[1]*a[n];find(n-1);a[1]:=i;
if a[n]<>0 then
a[1]:=a[1]/a[n];find(n-1);a[1]:=i;
a[1]:=a[n]/a[1];find(n-1);a[1]:=i;
end;
加法不要了?