Cod sursa(job #904745)

Utilizator classiusCobuz Andrei classius Data 4 martie 2013 20:16:40
Problema Fractal Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
//#include "stdafx.h"
#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 , y , x );
  return 0;
	
	return 0;
}