ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Common Board

1133. Is there anybody help me???... I did it but wa3.
Posted by Fibo 21 Jun 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;
}