2294 - L1024 的题解

回去原题
#举,但是不用每次加0.0001,用f(x)的精度就行。
var
  a,b,c,d,t,h,q1,q2:real;
  i:longint;
  f:boolean;
  ans:real;
function fun(i:real):real;
begin
  fun:=i*i*i*a+I*i*b+I*c+d;
end;
begin
  readln(a,b,c,d);
  f:=false;
  for i:=-100 to 100 do
  begin
    ans:=101.01;
    q1:=i*i*i*a+i*i*b+i*c+d;
    q2:=(i+1)*(i+1)*(i+1)*a+(i+1)*(i+1)*b+(i+1)*c+d;
    if q1*q2<0 then
    begin
      h:=i;
      t:=i+1;
      ans:=(H+t)/2;
      while (abs(fun(h)- fun(ans))>0.0001) or (abs(fun(t)-fun(ans))>0.0001) do
      begin
        if fun(ans)*fun(h)<0 then
        begin
          t:=ans;
          ans:=(H+t)/2;
        end;
        if fun(ans)*fun(t)<0 then
        begin
          h:=ans;
          ans:=(H+t)/2;
        end;
      end;
    end;
    if q1=0 then
      ans:=i;
    if (ans<=100) and (ans>=-100) then
      if f then  write(' ',ans:0:2)
      else
      begin
        f:=true;
        write(ans:0:2);
      end;
  end;
  writeln;
end.