Cod sursa(job #1444393)

Utilizator LegionHagiu Stefan Legion Data 29 mai 2015 18:26:06
Problema Fractal Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.86 kb
#include <iostream>
#include <fstream>
using namespace std;
long long rez(int k, int x, int y)
{
	if (k == 2)
	{
		if (x == 1 && y == 1)
		{
			return 0;
		}
		else if (x == 1 && y == 2)
		{
			return 3;
		}
		else if (x == 2 && y == 1)
		{
			return 1;
		}
		else if (x == 2 && y == 2)
		{
			return 2;
		}
	}
	else
	{
		if (x <= k / 2)
		{
			if (y <= k / 2)
			{
				return rez(k / 2, y, x);
			}
			else
			{
				return k/2*k/2*3+rez(k / 2,k-y+1,k/2-x+1);
			}
		}
		else
		{
			if (y <= k / 2)
			{
				return k / 2*k/2 + rez(k / 2, x-k/2, y);
			}
			else
			{
				return k / 2 * k + rez(k / 2, x - k / 2, y - k / 2);
			}
		}
	}
}
int main()
{
	ifstream in("fractal.in");
	ofstream out("fractal.out");
	int x, y, k,i,d=1;
	in >> k;
	in >> y;
	in >> x;
	for (i = 1; i <= k; i++)
	{
		d *= 2;
	}
	out << rez(d,x,y);
}