Pagini recente » Cod sursa (job #2374504) | Cod sursa (job #296117) | Cod sursa (job #2115374) | Cod sursa (job #1582481) | Cod sursa (job #2737628)
#include <fstream>
#include <algorithm>
#include <climits>
#include <iostream>
long long divide (int k, int x, int y) {
if (k == 1) {
if (x == 1 && y == 1) {
return 0;
}
if (x == 2 && y == 1) {
return 3;
}
if (x == 1 && y == 2) {
return 1;
}
return 2;
}
long long bound = (1 << (k - 1));
if (x <= bound && y <= bound) {
return divide(k - 1, y, x);
}
if (x <= bound && y > bound) {
return (bound * bound) + divide(k - 1, x, y - bound);
}
if (x > bound && y > bound) {
return (2LL * bound * bound) + divide(k - 1, x - bound, y - bound);
}
return (3LL * bound * bound) + divide(k - 1, 2 * bound - y + 1, bound - x + 1);
}
int main() {
std::ifstream fin("fractal.in");
std::ofstream fout("fractal.out");
int k, x, y;
fin >> k >> x >> y;
fout << divide(k, x, y);
return 0;
}