Cod sursa(job #2490633)

Utilizator miruna1224Floroiu Miruna miruna1224 Data 10 noiembrie 2019 16:45:47
Problema Fractal Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.8 kb
	
#include <fstream>
#include <iostream>

using namespace std;


int p[18];


int fractal(int k, int x, int y)
{
	if(k == 0) return 0;
	if(x <= p[k - 1] && y <= p[k - 1])
		return fractal(k - 1, y, x);
        if(x <= p[k - 1] && y > p[k - 1])
		return fractal(k - 1, x, y - p[k - 1]) + p[k - 1] * p[k - 1];
	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;
	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;

	if ( k == 1 ){
		g << 0;
		f.close();
		g.close();
		return 0;
	}
	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;
}