Cod sursa(job #328155)

Utilizator radu_cppRadu Voroneanu radu_cpp Data 1 iulie 2009 10:06:46
Problema Fractal Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.72 kb
#include<stdio.h>

int k,x,y;

int rec(int k, int x, int y)
{
	int t,zone,x0,y0;
	t=(1 << (k-1));
	if (x<=t && y<=t) zone=0;
	if (x<=t && y>t) zone=3;
	if (x>t && y<=t) zone=1;
	if (x>t && y>t) zone=2;
	if (k==1) return zone;
	x0=x; y0=y;
	if (zone == 0){
		y=x0;
		x=y0;
		return rec(k-1,x,y);
	}
	if (zone == 1){
		x=x0-t;
		return t*t+rec(k-1,x,y);
	}
	if (zone == 2){
		x=x0-t;
		y=y0-t;
		return 2*t*t+rec(k-1,x,y);
	}
	if (zone == 3){
		x=2*t-y0+1;
		y=t-x0+1;
		return t*t*3+rec(k-1,x,y);
	}
}

int main()
{
	freopen("fractal.in","r",stdin);
	freopen("fractal.out","w",stdout);
	scanf("%ld%ld%ld",&k,&x,&y);
	printf("%ld\n",rec(k+1,x,y));
	fclose(stdin); fclose(stdout);
	return 0;
}