Pagini recente » Cod sursa (job #1794844) | Cod sursa (job #811212) | Cod sursa (job #2211749) | Cod sursa (job #1166525) | Cod sursa (job #466449)
Cod sursa(job #466449)
#include <fstream>
#include <vector>
#include <cassert>
using namespace std;
const long long MAXV = 1000000000000000LL;
int N;
vector <long long> fib;
int main() {
ifstream fin("fibo3.in");
ofstream fout("fibo3.out");
fin >> N;
assert(1 <= N && N <= 100000);
fib.push_back(1);
fib.push_back(2);
for (int i = 0; fib[i] + fib[i+1] <= MAXV; ++i)
fib.push_back(fib[i] + fib[i+1]);
for (int i = 1; i <= N; ++i) {
long long x1, x2, y1, y2, sol = 0;
fin >> x1 >> y1 >> x2 >> y2;
assert(0 <= x1 && x1 <= x2 && x2 <= MAXV);
assert(0 <= y1 && y1 <= y2 && y2 <= MAXV);
long long p1 = min(x1+y2, x2+y1);
long long p2 = max(x1+y2, x2+y1);
for (size_t j = 0; j < fib.size() && fib[j] <= x2+y2; ++j) {
if (fib[j] >= x1+y1) {
if (fib[j] < p1) {
sol += fib[j]-(x1+y1) + 1;
} else if (fib[j] > p2) {
sol += x2+y2 - fib[j] + 1;
} else {
sol += min(x2-x1, y2-y1) + 1;
}
}
}
fout << sol << '\n';
}
return 0;
}