Cod sursa(job #568586)

Utilizator rootsroots1 roots Data 31 martie 2011 14:25:14
Problema Fractal Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.54 kb
#include <stdio.h>

int sol=0;

void crack(int K,int x,int y)
{
	if(K>0)
	{
		int pow=1<<(K-1);

		if(x<=pow&&y<=pow) crack(K-1,y,x);
		else
		if(x>pow&&y<=pow) sol+=pow*pow, crack(K-1,x-pow,y);
		else
		if(x>pow&&y>pow) sol+=2*pow*pow, crack(K-1,x-pow,y-pow);
		else
		if(x<=pow&&y>pow) sol+=3*pow*pow, crack(K-1,2*pow-y+1,pow-x+1);
	}
}

int main()
{
	int K,x,y;

	freopen("fractal.in","r",stdin);

	scanf("%d%d%d",&K,&x,&y);
	crack(K,y,x);

	freopen("fractal.out","w",stdout);

	printf("%d\n",sol);
	return 0;
}