Pagini recente » Cod sursa (job #2325471) | Cod sursa (job #1839426) | Cod sursa (job #999525) | Cod sursa (job #2637955) | Cod sursa (job #2136441)
#include <cstdio>
using namespace std;
int dist[2][2] = {0, 3, 1, 2};
int x, y, k;
int divide(int k, int x, int y) {
if(k == 1) {
return dist[x - 1][y - 1];
} else {
if (y <= 1 << (k - 1)) {
if (x <= 1 << (k - 1)) {
return divide(k - 1, y, x);
} else {
return divide(k - 1, x - (1 << (k - 1)), y) + (1 << 2 * (k - 1));
}
} else {
if (x > 1 << (k - 1)) {
return divide(k - 1, x - (1 << (k - 1)), y - (1 << (k - 1))) + 2 * (1 << 2 * (k - 1));
} else {
return divide(k - 1, (1 << k) - y + 1, (1 << (k - 1)) - x + 1) + 3 * (1 << 2 * (k - 1));
}
}
}
}
int main()
{
freopen("fractal.in", "rt", stdin);
freopen("fractal.out", "wt", stdout);
scanf("%d%d%d", &k, &y, &x);
printf("%d\n", divide(k, x, y));
return 0;
}