Cod sursa(job #641574)

Utilizator thesilverhand13FII Florea Toma Eduard thesilverhand13 Data 28 noiembrie 2011 21:31:04
Problema Fractal Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.64 kb
#include <fstream>

using namespace std;

ifstream f("fractal.in");
ofstream g("fractal.out");

int n , x , y , k = 1 , i;

int calc( int k, int x, int y )
{
	
  if ( k == 0 ) 
	  return 0;
  if ( ( x <= k ) && ( y <= k ) )
	  return calc (k / 2 , y, x );
  if ( ( x > k ) && ( y <= k ) ) 
	  return k * k + calc ( k / 2 , x - k , y );
  if ( ( x > k ) && ( y > k ) )
	  return 2 * k * k + calc ( k / 2 , x - k , y - k );
  if ( ( x <= k ) && ( y > k ) )
	  return 3 * k * k + calc ( k / 2 , 2 * k - y + 1 , k - x + 1 );
}

int main()
{
  
  f >> n >> x >> y;
  for ( i = 1 ; i <= n - 1 ; i++ ) 
	  k *= 2;
  g << calc ( k , x , y );
  return 0;
}