Cod sursa(job #514400)

Utilizator tamas_iuliaTamas Iulia tamas_iulia Data 18 decembrie 2010 17:07:39
Problema Fibo3 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.9 kb
#include <stdio.h>
#define Nmax 100002
#define Fmax 102
#define Vmax 2000000000000000
#define LL long long

LL F[Fmax],sol;
int T;

inline LL Abs(LL x){ return x>0? x:-x; }
inline LL Minim(LL x,LL y){ return x<y ? x:y; }
int main(){
    int i,j,x1,x2,y1,y2,N;
    freopen("fibo3.in","r",stdin);
    freopen("fibo3.out","w",stdout);
    F[1]=1; F[2]=2;
    for(i=3; F[i-1]+F[i-2]<=Vmax; ++i) F[i]=F[i-2]+F[i-1];
    N=i-1;

    scanf("%d",&T);
    for(i=1;i<=T;++i){
        scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
        sol=0;
            for(j=1; j<=N; ++j){
                if( F[j]<x1+y1 ) continue;
                if( F[j]>x2+y2 ) break;
                if( F[j]<=x1+y2)
                    sol+=Minim(F[j]-x1-y1+1,x2-x1+1);
                else sol += Minim(x2+y2-F[j]+1,y2-y1+1);
            }

        printf("%lld\n",sol);
    }

    fclose(stdin); fclose(stdout);
    return 0;
}