Cod sursa(job #491901)

Utilizator ChallengeMurtaza Alexandru Challenge Data 12 octombrie 2010 19:24:28
Problema Fractal Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.62 kb
#include <fstream>

using namespace std;

const char InFile[]="fractal.in";
const char OutFile[]="fractal.out";
const int MaxK=20;

ifstream fin(InFile);
ofstream fout(OutFile);

int k,x,y,a[MaxK],l,cf,rotation;

int cost(int k,int x,int y)
{
	if(k==0)
	{
		return 0;
	}
	int v=1<<(k-1);
	if(x<=v)
	{
		if(y<=v)
		{
			return cost(k-1,y,x);
		}
		else
		{
            return v*v+cost(k-1,x,y-v);
		}
	}
	if(y<=v)
	{
		return 3*v*v+cost(k-1,v-y+1,v-x+1);
	}
	else
	{
        return 2*v*v+cost(k-1,x-v,y-v);
	}
}

int main()
{
    fin>>k>>x>>y;
    fin.close();
    int sol=cost(k,x,y);
    fout<<sol;
    fout.close();
    return 0;
}