Cod sursa(job #466111)

Utilizator sodamngoodSo Damn Good sodamngood Data 26 iunie 2010 10:25:11
Problema Fibo3 Scor 30
Compilator cpp Status done
Runda Stelele Informaticii 2010, gimnaziu si clasa a IX-a, Ziua 2 Marime 1.05 kb
#include <iostream>
using namespace std;
#define maxc 1000000000000000LL

int N, nr;
long long A[80];

void genfibo() {
    A[1] = 1; A[2] = 1; nr = 2;
    while(A[nr-1] + A[nr] < maxc) {
         nr++;
         A[nr] = A[nr-1] + A[nr-2];
    }
}

int main() {
    FILE *f1=fopen("fibo3.in", "r"), *f2=fopen("fibo3.out", "w");
    int i, j;
    long long x, y, x1, x2, y1, y2;

    genfibo();

    fscanf(f1, "%d\n", &N);
    while(N--) {
         int sum = 0;
         fscanf(f1, "%lld %lld %lld %lld\n", &x1, &y1, &x2, &y2);
         //pe verticala
         for(i=2; i<=nr; i++) {
              y = A[i] - x1;
              if(y1 <= y && y < y2) {
                   sum += min(x2 - x1 + 1, y - y1 + 1);
              }
         }
         //pe orizontala
         for(i=2; i<=nr; i++) {
              x = A[i] - y2;
              if(x1 <= x && x <= x2) {
                   sum += min(x2 - x + 1, y2 - y1 + 1);
              }
         }

         fprintf(f2, "%d\n", sum);
    }
    
    fclose(f1); fclose(f2);
    return 0;
}