Cod sursa(job #815271)

Utilizator TzenyTenescu Andrei Tzeny Data 16 noiembrie 2012 19:28:07
Problema Fractal Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <fstream>

using namespace std;

ifstream fin("fractal.in");
ofstream fout("fractal.out");

int power(int a, int b)
{
	int or_a=a;
	if(b==0)
		return 1;
	if(b==1)
		return a;
	for(int i=1;i<b;i++)
		a*=or_a;
	return a;
}

int round_up(int a)
{
	int i=0;
	while(a>power(2,i))
		i++;
	return i;
}

int main()
{
	int x,y,k,square_size;
	
	fin>>k>>x>>y;
	
	int steps = 3;
	for(int i=2;i<k;i++)
	{
		steps*=4;
	}
	steps+=3;
	if(k==1)
		fout<<0;
	else
	{
		int pow;
		
		pow = power(2,k);
		
		if(x<=pow/2)
		{
			if(y<=pow/2)
				steps-=3;
			else
				steps-=2;
		}
		if(x>=pow/2+1)
		{
			if(y>=pow/2+1)
				steps--;
		}
		
		fout << steps;
	}
}