Pagini recente » Cod sursa (job #3284261) | Cod sursa (job #2669521) | Cod sursa (job #3170177) | Cod sursa (job #2613799) | Cod sursa (job #2488638)
#include <bits/stdc++.h>
using namespace std;
long long pw2[100];
int divide(int x, int y, int dim) {
if (dim == 1) {
if (x == 1 && y == 1) {
return 0;
}
if (x == 1 && y == 2) {
return 3;
}
if (x == 2 && y == 1) {
return 1;
}
if (x == 2 && y == 2) {
return 2;
}
} else {
if (x <= pw2[dim - 1] && y <= pw2[dim - 1] ) {
return divide(y, x, dim - 1);
}
else if (x <= pw2[dim - 1] && y > pw2[dim - 1]) {
return 3 * pw2[dim] + divide(pw2[dim - 1] - y + pw2[dim - 1] + 1, pw2[dim - 1] - x + 1, dim - 1);
}
else if (x > pw2[dim - 1] && y <= pw2[dim - 1]) {
return pw2[dim] + divide(x - pw2[dim - 1], y, dim - 1);
}
else if (x > pw2[dim - 1] && y > pw2[dim - 1]) {
return 2 * pw2[dim] + divide(x - pw2[dim - 1], y - pw2[dim - 1], dim - 1);
}
}
}
int main()
{
ifstream f("fractal.in");
ofstream g("fractal.out");
pw2[0] = 1;
int x, y, k;
cin >> k >> x >> y;
for (int i = 1; i <= k; i++) {
pw2[i] = 2 * pw2[i - 1];
//cout << pw2[i] << endl;
}
cout << divide(y, x, k);
}