Cod sursa(job #801451)

Utilizator tibi9876Marin Tiberiu tibi9876 Data 24 octombrie 2012 13:46:40
Problema Fractal Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.51 kb
#include<fstream>
using namespace std;

int k,x,y,v[20],s,i;

void T(int k,int x,int y)
{
	if (k==0)
		return;
	int p=1 << (k-1);
	if ((x<=p) && (y<=p))
		T(k-1,x,y);
	else if (x<=p)
	{
		s+=v[k-1]+1;
		T(k-1,x,y-p);
	}
	else if (y<=p)
	{
		s+=3*v[k-1]+3;
		T(k-1,x-p,y);
	}
	else 
	{
		s+=2*v[k-1]+2;
		T(k-1,x-p,y-p);
	}
}		

int main()
{
	ifstream f("fractal.in");
	ofstream g("fractal.out");
	f >> k >> x >> y;
	for (i=1;i<=k;i++)
		v[i]=v[i-1]*4+3;
	s=0;
	T(k,x,y);
	g << s;
}