|
|
вернуться в форумОбщий форум1133. Is there anybody help me???... I did it but wa3. Послано Fibo 21 июн 2010 00:16 #include <cstdlib> #include <iostream> using namespace std; int bas = -2000000001; int son = 2000000001; int i,n,j,y,t; int Fi, Fj, Fn; int Fibo(int m); int main(int argc, char *argv[]) { int h=0; cin >> i >> Fi >> j >> Fj >> n;
if(i > j){swap(i,j); swap(Fi,Fj);} t=abs(n);y=abs(i); if(n<i && n<0){n=0; i=i+t; j=j+t;} else if(i<0 && i<n) { i=0; n=n+y; j=j+y;}
// cout << i << " " << j <<" " << n; int bas = -2000000001; int son = 2000000001; int m; if(j==i+1) {h=1;m=Fj;} else{
while(bas <=son) { m =(bas +son)/2; if(Fibo(m)==Fj) { break;} else if(Fibo(m)>Fj){ son= m;} else {bas = m ;} }
}
if(n>i){ for(int e=i+1;e<n;e++){ Fn = Fi + m; Fi = m; m=Fn;}cout << Fn;} else if(n==i) cout << Fi; else if(n==j) cout << Fj; else if(n < i) { for(int e=n+1;e<=i;e++){ Fn = m-Fi; m = Fi; Fi = Fn;
} cout << Fn; } return 0; } int Fibo(int m) { int r=m; int fk; fk=Fi; int ans=0; for(int k=i+1; k<j; k++) {ans = fk +r; fk=r; r=ans;} return ans; } |
|
|