Cod sursa(job #568637)

Utilizator stay_awake77Cangea Catalina stay_awake77 Data 31 martie 2011 15:50:48
Problema Fractal Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.62 kb
#include<stdio.h>
#define ll long long

ll K, x, y;

inline ll Steps( int Ord, int X, int Y )
{
	if( Ord )
	{
		int L = ( 1<<(Ord-1) );

		if( Y <= Ord && X <= Ord ) return Steps( Ord-1, Y, X );
		else if( Y <= Ord && X > Ord ) return L*L + Steps( Ord-1, X-L, Y );
		else if( Y > Ord && X > Ord ) return 2*L*L + Steps( Ord-1, X-L, Y-L );
		else if( Y > Ord && X <= Ord ) return 3*L*L + Steps( Ord-1, 2*L-Y+1, L-X+1 );
	}

	return 0;
}

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

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

	printf("%d\n", Steps( K, y, x ));

	return 0;
}