Cod sursa(job #2634638)

Utilizator euyoTukanul euyo Data 11 iulie 2020 20:00:09
Problema Fractal Scor 80
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.52 kb
#include <fstream>
#include <algorithm>

using namespace std;

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

static inline void case1( int M[2][2] ) {
  //int a = M[0][1], b = M[1][1], c = M[0][0], d = M[1][0];
  //M[0][0] = a, M[0][1] = b, M[1][0] = c, M[1][1] = d; 
  swap( M[0][1], M[1][0] );
}
static inline void case2( int M[2][2] ) {
  //int a = , b = , c = , d = ;
  //M[0][0] = a, M[0][1] = b, M[1][0] = c, M[1][1] = d;
  swap( M[0][0], M[1][1] );
}

static inline int np( int lat ) {
  return lat * lat;
}

int mm[2][2] = { { 0, 3 }, { 1, 2 } };

int moves( int lat, int x, int y, int m[2][2] ) {
  int a = m[0][0], b = m[1][0], c = m[1][1], d = m[0][1];

  //printf( "%d %d %d %d\n", a, b, c, d );  
  if ( lat == 1 ) {
	//printf( "m:%d %d %d\n", x, y, m[x][y] );
	return 0;
  }
  //printf( "%d ", lat / 2 );
  if ( x < lat / 2 && y < lat / 2 ) {
	//printf( "%d\n", a );
	case1( m );
	return moves( lat / 2, x, y, m ) + a * np( lat / 2 );
  } else if ( x < lat / 2 && y >= lat / 2 ) {
	//printf( "%d\n", b );
	return moves( lat / 2, x, y - lat / 2, m ) + b * np( lat / 2 );
  } else if ( x >= lat / 2 && y >= lat / 2 ) {
	//printf( "%d\n", c );
    return moves( lat / 2, x - lat / 2, y - lat / 2, m ) + c * np( lat / 2 );
  } else if ( x >= lat / 2 && y < lat / 2 ) {
	//printf( "%d\n", d );
	case2( m );
	return moves( lat / 2, x - lat / 2, y, m ) + d * np( lat / 2 );
  }
}

int main() {
  int k, x, y;
  
  fin >> k >> x >> y;
  --x;
  --y;
  fout << moves( (1 << k), x, y, mm );
  fin.close();
  fout.close();
  return 0;
}