what's wrong with my program?
Posted by
Sum 1 5 Feb 2003 20:11
var
i, j, n, p, q: longint;
Fi, Fj, Fi1, Fn: extended;
F: array [1..2, 1..2] of extended;
begin
readln(i, Fi, j, Fj, n);
F[1, 1] := 1; F[1, 2] := 0;
F[2, 1] := 0; F[2, 2] := 1;
if i < j then begin
q := 2;
for p := i + 2 to j do begin
q := 3 - q;
F[q, 1] := F[q, 1] + F[3 - q, 1];
F[q, 2] := F[q, 2] + F[3 - q, 2];
end;
end
else begin
q := 1;
for p := i - 1 downto j do begin
q := 3 - q;
F[q, 1] := F[q, 1] - F[3 - q, 1];
F[q, 2] := F[q, 2] - F[3 - q, 2];
end;
end;
Fi1 := (Fj - Fi * F[q, 1]) / F[q, 2];
F[1, 1] := 1; F[1, 2] := 0;
F[2, 1] := 0; F[2, 2] := 1;
if i < n then begin
q := 2;
for p := i + 2 to n do begin
q := 3 - q;
F[q, 1] := F[q, 1] + F[3 - q, 1];
F[q, 2] := F[q, 2] + F[3 - q, 2];
end;
end
else begin
q := 1;
for p := i - 1 downto n do begin
q := 3 - q;
F[q, 1] := F[q, 1] - F[3 - q, 1];
F[q, 2] := F[q, 2] - F[3 - q, 2];
end;
end;
Fn := Fi * F[q, 1] + Fi1 * F[q, 2];
if Fn = 0 then writeln(0) else writeln(Fn: 0: 0);
end.