Pagini recente » Cod sursa (job #1719372) | Cod sursa (job #3206579) | Cod sursa (job #1687614) | Cod sursa (job #2266869) | Cod sursa (job #2021949)
#include <cstdio>
#include <vector>
#include <algorithm>
FILE *fin, *fout;
#define MAXNR 2e15 + 1
#define ll long long
int N;
std::vector <ll> fibi;
ll X1, Y1, X2, Y2;
bool ok = 1;
inline void calc(ll x, ll x1, ll y1, ll x2, ll y2) {
ok = 1;
X1 = x - y1;
Y1 = x - x1;
if (!(X1 >= x1 && X1 <= x2)) {
X1 = x1;
}
else
Y1 = y1;
X2 = x - y2;
Y2 = x - x2;
if (!(X2 >= x1 && X2 <= x2)) {
X2 = x2;
}
else
Y2 = y2;
}
int main() {
fin = fopen("fibo3.in", "r");
fout = fopen("fibo3.out", "w");
fscanf(fin, "%d", &N);
fibi.push_back(1);
fibi.push_back(1);
while (fibi.back() <= MAXNR)
fibi.push_back(fibi.back() + fibi[fibi.size() - 2]);
fibi.pop_back();
for (int i = 1; i <= N; i++) {
ll x1, y1, x2, y2;
fscanf(fin, "%lld%lld%lld%lld", &x1, &y1, &x2, &y2);
if (x1 > x2)
std::swap(x1, x2);
if (y1 < y2) {
std::swap(y1, y2);
}
ll low, high;
low = std::min(x1, x2) + std::min(y1, y2);
high = std::max(x1, x2) + std::max(y1, y2);
ll ans = 2LL;
if (low == high)
ans--;
if (low == 0)
ans--;
// printf("%lld %lld %lld %lld\n", x1, y1, x2, y2);
for (unsigned int j = 1; j < fibi.size();j++) {
ll x = fibi[j];
if (x > low && x < high) {
calc(x, x1, y1, x2, y2);
if (ok == 1) {
ll dif = X2 - X1 + 1;
if (!(X1 == x1 && Y1 == y1 && X2 == x2 && Y2 == y2) && !(x1 == x2 || y1 == y2)) {
dif *= 2LL;
}
// if (i == 2) {
// printf("%lld %lld %lld %lld\n", X1, Y1, X2, Y2);
// }
ans += dif;
}
}
else if (x > high)
j = fibi.size();
}
fprintf(fout, "%lld\n", ans);
}
fclose(fin);
fclose(fout);
return 0;
}