Cod sursa(job #568545)

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

int sol=0;
int c1,c2,c3,c4;

void swap(int &a,int &b)
{
	int aux;
	aux=a;
	a=b;
	b=aux;
}

void crack(int K,int x,int y,int type)
{
	if(K>0)
	{
		int L,M,R;

		L=0;
		M=1<<(K-1);
		R=1<<K;

		if(L<x&&x<=M)
		{
			if(L<y&&y<=M)
			{
				sol+=c1*M*M;
				if(type==1) swap(c2,c3);
				else
				if(type==2) swap(c2,c3);
				crack(K-1,x,y,1);
			}
			else
			if(M<y&&y<=R)
			{
				sol+=c2*M*M;
				if(type==2) swap(c1,c4);
				else
				if(type==3) swap(c1,c4);
				crack(K-1,x,y-M,3);
			}
		}
		else
		if(M<x&&x<=R)
		{
			if(L<y&&y<=M)
			{
				sol+=c3*M*M;
				if(type==1) swap(c1,c4);
				crack(K-1,x-M,y,2);
			}
			else
			if(M<y&&y<=R)
			{
				sol+=c4*M*M;
				if(type==3) swap(c2,c3);
				crack(K-1,x-M,y-M,2);
			}
		}
	}
}

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

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

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

	c1=0;
	c2=3;
	c3=1;
	c4=2;
	crack(K,y,x,2);

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

	printf("%d\n",sol);

	return 0;
}