Cod sursa(job #466521)

Utilizator miculprogramatorA Cosmina - vechi miculprogramator Data 26 iunie 2010 21:44:23
Problema Fibo3 Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.96 kb
#include <stdio.h>
#include <algorithm>
using namespace std;

long long fib[120];
int n, i, j, k;
int lg = 2, puncte;
long long x, y, x1, x2, y1, y2;

int main()
{
    FILE *f = fopen ("fibo3.in", "r");
    FILE *g = fopen ("fibo3.out", "w");
    fscanf (f,"%d", &n);

    fib[1] = fib[2] = 1;
    for (i=3; i<=110; ++i)
    {
        lg ++;
        fib[i] = fib[i-1] + fib[i-2];
    }

    for (k=1; k<=n; ++k)
    {
        fscanf (f, "%lld %lld %lld %lld", &x1, &y1, &x2, &y2);
        puncte = 0;

        for (i=2; i<=lg; ++i)
        {
            y = fib[i] - x1;
            if (y1 <= y && y < y2)
                puncte += min(x2 - x1 + 1, y - y1 + 1);
        }

        for (i=2; i<=lg; ++i)
        {
            x = fib[i] - y2;
            if (x1 <= x && x <= x2)
                puncte += min(x2 - x + 1, y2 - y1 + 1);

        }

        fprintf(g, "%d\n", puncte);
    }

    fclose(g);
    fclose(f);
    return 0;
}