Cod sursa(job #402537)

Utilizator ConsstantinTabacu Raul Consstantin Data 23 februarie 2010 22:28:19
Problema Fractal Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.94 kb
#include<stdio.h>
int l[ 20 ],i,j,k,m,n,x,y,px,py,ux,uy,sol;

int main(){
	freopen("fractal.in","r",stdin);
	freopen("fractal.out","w",stdout);
	
	scanf("%d %d %d",&k,&x,&y);
	for(i = 1 ; i <= k ; i++)
		l[i] = 4*l[i-1]+3;
	px = 1;ux = (1<<k);
	py = 1;uy = (1<<k);
	for(i = k ; i >= 1 ; i--)
		{n = (px + ux)>>1;
		m = (py + uy)>>1;
		if(n >= x && m < y)
			{ux = n;py = m+1;sol+=l[i-1]+1;}
		else
		if(n < x && m < y)
			{px = n+1;py = m+1;sol += 2*l[i-1]+2;}
		else
		if(n >= x && m >= y)
			{ux = n;uy = m;
			ux = ux - px + 1;
			x = x - px + 1;
			uy = uy - py + 1;
			y = y - py + 1;
			px = py = 1;
			j = x;
			x = y;
			y = j;
			}
		else
		if(n < x && m >= y)
			{px = n+1;
			uy = m;
			ux = ux - px +1;
			uy = uy - py +1;
			x  =  x - px +1;
			y  =  y - py +1;
			px = py = 1;
			j = y;
			y = ux - x + 1;
			x = j;
			x = ux - x + 1;
			sol += 3*l[i-1] + 3;
			}
		}
printf("%d",sol);
return 0;}