Cod sursa(job #466113)

Utilizator miculprogramatorA Cosmina - vechi miculprogramator Data 26 iunie 2010 10:25:47
Problema Fibo3 Scor 0
Compilator cpp Status done
Runda Stelele Informaticii 2010, gimnaziu si clasa a IX-a, Ziua 2 Marime 1.39 kb
#include <stdio.h>
#include <vector>
using namespace std;

#define LIM 42

long long fib[] = {0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269, 2178309, 3524578, 5702887, 9227465, 14930352, 24157817, 39088169, 63245986, 102334155};
long long x1, y1, x2, y2;
long long i, j, k, p;
long int puncte, n;

int cautare_binara (long long x)
{
    int st, dr, mijl;
    st = 1;
    dr = LIM;
    while (st <= dr)
    {
        mijl = (st + dr) / 2;
        if (fib[mijl] == x)
            return 1;
        else if (fib[mijl] > x)
            dr = mijl - 1;
        else if (fib[mijl] < x)
            st = mijl + 1;
    }
    return 0;
}

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

    fscanf (f,"%ld", &n);

    for (k=1; k<=n; ++k)
    {
        fscanf (f,"%lld %lld %lld %lld", &x1, &y1, &x2, &y2);
        puncte = 0;
        for (i=x1; i<=x2; ++i)
            for (j=y1; j<=y2; ++j)
            {
                //printf ("%lld %lld\n", i, j);
                if (cautare_binara(i + j))
                    puncte ++;
            }
        //printf ("puncte = %ld\n", puncte);
        //printf ("\n\n");
        fprintf (g,"%ld\n", puncte);
    }


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