Pagini recente » Cod sursa (job #2328991) | Cod sursa (job #1512892) | Cod sursa (job #2473437) | Cod sursa (job #2630848) | Cod sursa (job #282490)
Cod sursa(job #282490)
#include <cstdio>
#define FIN "fractal.in"
#define FOUT "fractal.out"
int solve(int k, int x, int y)
{
int c, cx, cy;
if (k == 0)
return 0;
if (x <= (1 << (k - 1)) && y <= (1 << (k - 1)))
c = 0;
else if (x <= (1 << (k - 1)))
c = 1;
if (x > (1 << (k - 1)) && y <= (1 << (k - 1)))
c = 3;
else if ( x > (1 << (k - 1)))
c = 2;
if (c == 1 || c == 2)
{
cx = x - (1 << (k - 1)) * (c - 1);
cy = y - (1 << (k - 1));
}
if (c == 0)
{
cx = y;
cy = x;
}
if (c == 3)
{
cx = (1 << (k - 1)) - y + 1;
cy = (1 << k) - x + 1;
}
return (1 << (2 * k - 2)) * c + solve(k - 1, cx, cy);
}
int main()
{
int k,x,y;
freopen(FIN, "r", stdin);
freopen(FOUT, "w", stdout);
scanf("%d %d %d", &k, &x, &y);
printf("%d\n", solve(k, x, y));
}