Pagini recente » Cod sursa (job #2641594) | Cod sursa (job #1349327) | Cod sursa (job #2734720) | Cod sursa (job #2777977) | Cod sursa (job #2639702)
#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;
}