Cod sursa(job #1199940)

Utilizator IulianBoboUAIC Boboc Iulian IulianBobo Data 21 iunie 2014 11:53:32
Problema Fractal Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.75 kb
#include <fstream>
using namespace std;
int p[18];
int fractal(int k,int x,int y)
{
	if(x==1 && y==1) return 0;
	else if(x==1 && y==2) return 1;
	else if(x==2 && y==2) return 2;
	else if(x==2 && y==1) return 3;
	else
	{
		if(x<=p[k-1] && y<=p[k-1])
			return fractal(k-1,y,x);
		else if(x<=p[k-1] && y>p[k-1])
			return fractal(k-1,x,y-p[k-1]) + p[k-1]*p[k-1];
		else if(x>p[k-1] && y>p[k-1])
			return fractal(k-1,x-p[k-1],y-p[k-1]) + p[k-1]*p[k-1]*2;
		else return fractal(k-1,p[k-1]-y+1,p[k]-x+1) + 3*p[k-1]*p[k-1];
	}
}
int main()
{
	ifstream f("fractal.in");
	ofstream g("fractal.out");
	int k,x,y;
	f>>k>>x>>y;
	p[0]=1;
	for(int i=1;i<=k;i++) p[i]=p[i-1]*2;
	int result=fractal(k,x,y);
	g<<result;
	f.close();
	g.close();
	return 0;
}