Pagini recente » Cod sursa (job #472809) | Cod sursa (job #100720) | Cod sursa (job #1672198) | Cod sursa (job #1997241) | Cod sursa (job #1149382)
#include <cstdio>
#include <cstdint>
#include <algorithm>
using namespace std;
int main(int argc, char *argv[])
{
freopen("fractal.in", "r", stdin);
freopen("fractal.out", "w", stdout);
int a, s = 0, a2;
int k, x, y, cx;
scanf("%d%d%d", &k, &y, &x);
a = 1 << k;
while (k) {
a2 = a / 2;
if (x > a2 && y > a2) {
x -= a2;
y -= a2;
s += 2 * (1 << (k - 1) * 2);
}
else if (x <= a2 && y <= a2)
swap(x, y);
else if (x > a2 && y <= a2) {
x -= a2;
s += 1 << (k - 1) * 2;
}
else if (x <= a2 && y > a2) {
cx = x;
x = a - y + 1;
y = a2 - cx + 1;
s += 3 * (1 << (k - 1) * 2);
}
a >>= 1;
k--;
}
printf("%d\n", s);
return 0;
}