Cod sursa(job #2255401)

Utilizator alextodoranTodoran Alexandru Raul alextodoran Data 6 octombrie 2018 20:58:35
Problema Fibo3 Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.93 kb
#include <bits/stdc++.h>

using namespace std;

int n;

int main()
{
    ifstream fin ("fibo3.in");
    ofstream fout ("fibo3.out");
    fin >> n;
    while(n--)
    {
        long long ans = 0;
        long long x1, y1, x2, y2;
        fin >> x1 >> y1 >> x2 >> y2;
        if(x1 > x2)
            swap(x1, x2);
        if(y1 > y2)
            swap(y1, y2);
        for(long long a = 1, b = 1; b <= x2 + y2; swap(a, b), b = a + b)
            if(b >= x1 + y1)
            {
                if(y1 == y2 || x1 == x2)
                {
                    ans++;
                    continue;
                }
                if(b < min(x2 + y1, x1 + y2))
                    ans += b - (x1 + y1) + 1;
                else if(b > max(x2 + y1, x1 + y2))
                    ans += (x2 + y2) - b + 1;
                else ans += min(y2 - y1, x2 - x1) + 1;
            }
        fout << ans << "\n";
    }
    return 0;
}