백준 1074 Z
#include <iostream>
#include <math.h>
using namespace std;
int getResult(int N, int r, int c) {
if (N == 1) {
if (r == 0 && c == 0) return 0;
if (r == 0 && c == 1) return 1;
if (r == 1 && c == 0) return 2;
if (r == 1 && c == 1) return 3;
}
int half = pow(2, N - 1);
int full = pow(2, N);
if (r < half){
if (c < half)
return getResult(N - 1, r, c) + half * half * 0;
else if (c < full)
return getResult(N - 1, r, c - half) + half * half * 1;
}
else if (r < full) {
if (c < half)
return getResult(N - 1, r - half, c) + half * half * 2;
else if (c < full)
return getResult(N - 1, r - half, c - half) + half * half * 3;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int N, r, c;
cin >> N >> r >> c;
cout << getResult(N, r, c);
return 0;
}