Cod sursa(job #468169)

Utilizator ooctavTuchila Octavian ooctav Data 2 iulie 2010 15:13:54
Problema Fractal Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.08 kb
#include <cstdio>
#include <iostream>

using namespace std;

int x, y, k;
long long dim[15];
long long REZ = 0;
void calc_dim()
{
	for(int i = 1 ; i < 15 ; i++)
		dim[i] = 4 * dim[i - 1] + 3;
}

void rotire_1()
{
	int x2, y2;
	x2 = (1<<(k - 1)) - y + 1;
	y2 = x;
	x = x2;
	y = y2;

	x = (1<<(k - 1)) - x + 1;
}

void rotire_4()
{
	int x2, y2;
	x2 = y;
	y2 = (1<<(k - 1)) - x + 1;
	x = x2;
	y = y2;
	
	x = (1<<(k - 1)) - x + 1;
}

void impartire()
{
	if(y <= 1<<(k - 1)  && x <= 1<<(k - 1))
		rotire_1();
	else if(y > 1<<(k - 1)  && x <= 1<<(k - 1))
	{
		REZ += dim[k - 1] + 1;
		y -= 1<<(k - 1);
	}
	else if(y <= 1<<(k - 1)  && x > 1<<(k - 1)) 
	{		
		REZ += 3 *(dim[k - 1] + 1);
		x -= 1<<(k - 1);
		rotire_4();
	}
	else if(y > 1<<(k - 1)  && x > 1<<(k - 1))	
	{
		REZ += 2 *(dim[k - 1] + 1);
		y -= 1<<(k - 1);
		x -= 1<<(k - 1);
	}
}

int main()
{
	freopen("fractal.in", "r", stdin);
	freopen("fractal.out", "w", stdout);
	
	cin >> k >> x >> y;
	calc_dim();
	while(k)
	{
		impartire();
		k--;
	}
	printf("%d\n", REZ);
	
	return 0;
}