Cod sursa(job #2255495)

Utilizator alex2209alexPavel Alexandru alex2209alex Data 7 octombrie 2018 10:28:42
Problema Fibo3 Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.37 kb
#include <fstream>

using namespace std;
ifstream f("fibo3.in");
ofstream g("fibo3.out");
int n;
long long x1,x2,x,y1,y2,y,sum,a,b,c;
int main()
{
    f>>n;
    while(n--)
    {
        f>>x1>>y1>>x2>>y2;
        if(x1>x2)
        {
            swap(x1,x2);
        }
        if(y1>y2)
        {
            swap(y1,y2);
        }
        a=1;
        b=1;
        sum=0;
        while(b<=x2+y2)
        {
            if(x1+y1>b)
            {
                c=b;
                b=a+b;
                a=c;
                continue;
            }
            if(b-y1>=x1 && b-y1<=x2)
            {
                x=b-y1;
                x=x-x1+1;
                if(y1+x-1<=y2)
                {
                    sum+=x;
                }
                else
                {
                    sum+=y2-y1+1;
                }
            }
            else if(b-x2>=y1 && b-x2<=y2)
            {
                y=b-x2;
                y=y2-y+1;
                if(x2-y>=x1)
                {
                    sum+=y;
                }
                else
                {
                    sum+=x2-x1+1;
                }
            }
            else
            {
                break;
            }
            c=b;
            b=a+b;
            a=c;
        }
        g<<sum<<'\n';
    }
    return 0;
}