Cod sursa(job #897894)

Utilizator SebiDDanila Sebastian SebiD Data 27 februarie 2013 22:50:54
Problema Fractal Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.74 kb
// fractal - infoarena
#include <fstream>

using namespace std;

ifstream fin("fractal.in");
ofstream fout("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()
{

  fin >> n >> x >> y;
  for ( i = 1 ; i <= n - 1 ; i++ )
      k *= 2;
  fout << calc ( k , y , x );
  return 0;
  fin.close ();
  fout.close ();
}