Cod sursa(job #357789)

Utilizator proflaurianPanaete Adrian proflaurian Data 20 octombrie 2009 18:55:10
Problema Fractal Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.51 kb
#include<stdio.h>
int i,j,k,sol;
void read(),solve();
int main()
{
	read();
	solve();
	return 0;
}
void read()
{
	freopen("fractal.in","r",stdin);
	freopen("fractal.out","w",stdout);
	scanf("%d%d%d",&k,&j,&i);
}
void solve()
{
	int L,LL,R;
	while(i>1||j>1)
	{
		L=1<<k;LL=L>>1;R=LL*LL;
		if(i<=L/2)
		{
			if(j<=L/2){j^=i^=j^=i;}
			else {sol+=3*R+1;j=L-j;i=LL+1-i;}
		}
		else
		{
			if(j<=L/2){sol+=R+1;i-=LL;}
			else {sol+=2*R+1;i-=LL;j-=LL;}
		}
		k--;
	}
	printf("%d\n",sol);
}