CRUELL2 - Cô giáo dạy toán, phần II

Tác giả: RR

Ngôn ngữ: Pascal

{$R+,Q+}
uses math;
const
  FINP='';
  FOUT='';
  eps=0.00001;
var
  x,temp,left,right,mid:double;
  a:array[0..11] of double;
  n:longint;
function cal(x:double):double;
var
  i:longint;
  kq:double;
begin
  kq:=0;
  for i:=n downto 0 do
    kq:=kq*x+a[i];
  exit(kq);
end;
begin
  assign(input,FINP); reset(input);
  assign(output,FOUT); rewrite(output);
  read(n);
  for n:=0 to n do read(a[n]);
  left:=-1000000; right:=-left; x:=cal(left);
  repeat
    mid:=(left+right)/2;
    temp:=cal(mid);
    if abs(temp)<eps then begin writeln(trunc(mid*1000)); exit; end
    else
      if temp*x<0 then right:=mid
      else left:=mid;
  until left>right;
  close(input); close(output);
end.

Download