Pagini recente » Cod sursa (job #2156309) | Cod sursa (job #2715505) | Cod sursa (job #2517011) | Borderou de evaluare (job #3146043) | Cod sursa (job #789709)
Cod sursa(job #789709)
#include <cstdio>
int position(int, int, int);
int main()
{
int k, x, y, d;
freopen("fractal.in", "r", stdin);
freopen("fractal.out", "w", stdout);
scanf("%d %d %d", &k, &x, &y);
d = 1<<k;
printf("%d", position(d, x, y));
return 0;
}
int position(int ord, int x, int y)
{
if(ord == 1)
{
return 0;
}
ord /= 2;
if(x <= ord && y <= ord)
{
//return position(ord, y, ord-x);
return position(ord, y, x);
}
if(x <= ord && y > ord)
{
return ord * ord + position(ord, x, y-ord);
}
if(x > ord && y > ord)
{
return 2 * ord * ord + position(ord, x-ord, y-ord);
}
if(x > ord && y <= ord)
{
//return 3 * ord * ord + position(ord, ord-y, x-ord);
return 3 * ord * ord + position(ord, ord-y+1, 2*ord-x+1);
}
}