Cod sursa(job #1017173)

Utilizator tuzi92Tuzes-Katai Tamas tuzi92 Data 27 octombrie 2013 13:42:57
Problema Fractal Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.66 kb
#include <cstdio>
#include <cstdlib>

int megoldas(int k, int x, int y)
{
	if (k==0) return 0;
	if (x <= 1<<(k-1) && y <= 1<<(k-1)) 
		return megoldas(k-1, y, x);
	if (x > 1<<(k-1) && y > 1<<(k-1)) 
		return 2*(1<<(k-1))*(1<<(k-1)) + megoldas(k-1, x - 1<<(k-1), y - 1<<(k-1));
	if (x > 1<<(k-1) && y <= 1<<(k-1)) 
		return (1<<(k-1))*(1<<(k-1)) + megoldas(k-1, x - 1<<(k-1), y);
	return 3*(1<<(k-1))*(1<<(k-1)) + megoldas(k-1, 2 *(1<<(k-1)) - y + 1, 1<<(k-1) - x + 1);
}

int main()
{
	freopen("fractal.in", "r", stdin);
	freopen("fractal.out", "w", stdout);

	int k, x, y;

	scanf("%d%d%d", &k, &x, &y);
	printf("%d", megoldas(k, y, x));

	return 0;
}