Pagini recente » Cod sursa (job #1877998) | Cod sursa (job #465487) | Cod sursa (job #46742) | Cod sursa (job #1868448) | Cod sursa (job #481819)
Cod sursa(job #481819)
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
vector <long long> fib;
vector <long long> :: iterator it;
int n, i;
int lg = 2;
long long f1, f2, f_curent, 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.push_back (0);
f1 = f2 = 1;
fib.push_back (f1);
fib.push_back (f1);
for (i=3; i<=110; ++i)
{
lg ++;
f_curent = f1 + f2;
f1 = f2;
f2 = f_curent;
fib.push_back (f_curent);
}
for (i=1; i<=n; ++i)
{
fscanf (f, "%lld %lld %lld %lld", &x1, &y1, &x2, &y2);
puncte = 0;
for (it=fib.begin() + 2; it < fib.end(); ++it)
{
y = *it - x1;
if (y1 <= y && y < y2)
puncte += min (x2 - x1 + 1, y - y1 + 1);
}
for (it=fib.begin() + 2; it < fib.end(); ++it)
{
x = *it - y2;
if (x1 <= x && x <= x2)
puncte += min (x2 - x + 1, y2 - y1 + 1);
}
fprintf(g, "%lld\n", puncte);
}
fclose(g);
fclose(f);
return 0;
}