Cod sursa(job #2639702)

Utilizator euyoTukanul euyo Data 3 august 2020 15:50:15
Problema Fractal Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.79 kb
#include <fstream>
#include <algorithm>

using namespace std;

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

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

int moves( int lat, int x, int y ) {
  if ( lat == 1 ) {
	return 0;
  }
  if ( x <= lat / 2 && y <= lat / 2 ) {
	return moves( lat / 2, y, x );
  } else if ( x <= lat / 2 && y > lat / 2 ) {
	return moves( lat / 2, x, y - lat / 2 ) + np( lat / 2 );
  } else if ( x > lat / 2 && y > lat / 2 ) {
    return moves( lat / 2, x - lat / 2, y - lat / 2 ) + 2 * np( lat / 2 );
  } else if ( x > lat / 2 && y <= lat / 2 ) {
	return moves( lat / 2, lat / 2 - y + 1, lat - x + 1 ) + 3 * np( lat / 2 );
  }
}

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