Cod sursa(job #2021028)

Utilizator andrei_diaconu11Andrei C. Diaconu andrei_diaconu11 Data 12 septembrie 2017 16:18:59
Problema Fibo3 Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.08 kb
#include <bits/stdc++.h>

using namespace std;

long long fib[75];

int main()
{
    long long n, i, j, xin, xout, x1, x2, y1, y2, nr;
    FILE *fi = fopen("fibo3.in", "r"), *fo = fopen("fibo3.out", "w");
    fscanf(fi, "%lld", &n);
    fib[0] = fib[1] = 1;
    for(i = 2; i < 75; i++)
        fib[i] = fib[i - 1] + fib[i - 2];
    for(i = 0; i < n; i++){
        fscanf(fi, "%lld%lld%lld%lld", &x1, &y1, &x2, &y2);
        nr = 0;
        for(j = 1; j < 75; j++){
            xin = -1;
            if(x1 <= fib[j] - y1 && fib[j] - y1 <= x2)//sa intersecteze latura de jos
                xin = fib[j] - y1;
            else if(y1 <= fib[j] - x2 && y2 >= fib[j] - x2)//altfel,daca intersecteaza latura dreapta
                xin = x2;
            if(y1 <= fib[j] - x1 && fib[j] - x1 <= y2)//intersecteaza latura stanga
                xout = x1;
            else if(x1 <= fib[j] - y2 && fib[j] - y2 <= x2)
                xout = fib[j] - y2;
            if(xin != -1)
                nr += xin - xout + 1;
        }
        fprintf(fo, "%lld\n", nr);
    }
    return 0;
}