http://acm.timus.ru/problem.aspx?space=1&num=1133
题目大意:给定i Fi,j,Fj,n.求Fn。
满足:Fi+2=Fi+1+Fi;
应该说是水题一个哇:
Fi+k = gk * Fi + gk-1 * Fi-1。其中g是1 1 开头的fibonacci数。
C/C++的long long double都过不了。pascal的extended过了。怎么回事呢??
Pascal代码:
Var
i,j,k,p,n,tmp:longint;
F:array[-1001..1001] of extended;
g:array[0..2002] of extended;
temp,ti,tj:extended;
begin
readln(i,ti,j,tj,n);
F[i]:=ti;F[j]:=tj;
if (i>j) then
begin
tmp:=i;i:=j;j:=tmp;
F[i]:=tj;F[j]:=ti;
end;
k:=j-i;
g[0]:=1;g[1]:=1;
for p:=2 to k do
g[p]:=g[p-1]+g[p-2];
F[i-1]:=trunc((F[j]-F[i]*g[k])/g[k-1]);
if n>i then
begin
k:=i+1;
while k<=n do
begin
F[k]:=F[k-1]+F[k-2];
inc(k);
end;
end;
if n<i-1 then
begin
k:=i-2;
while k>=n do
begin
F[k]:=F[k+2]-F[k+1];
dec(k);
end;
end;
writeln(F[n]:0:0);
readln;
end.
昨天真是被这个题目虐惨了啊!!!!!!
尼玛,我们真是弱爆了!