백준 1074 c++
#include <iostream>
#include <cmath>
using namespace std;
int N, r, c;
int cnt = 0;
int input(int lower, int upper)
{
//cout << "input()" << endl;
int A;
while (1)
{
cin >> A;
if (A >= lower && A <= upper)
{
break;
}
else
{
;
}
}
return A;
}
void find_Z(int x, int y, int size)
{
if (x == c && y == r) //
{
cout << cnt << "\n";
return;
}
else if ((x <= c && c < x + size)&&(y <= r && r < y + size)) //범위 안인 경우
{
find_Z(x, y, size / 2);
find_Z(x + size / 2, y, size / 2);
find_Z(x, y + size / 2, size / 2);
find_Z(x + size / 2, y + size / 2, size / 2);
}
else // 범위 밖인 경우
{
cnt += size * size;
return;
}
}
int main(void)
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
N = input(1, 15);
r = input(0, pow(2, N));
c = input(0, pow(2, N));
find_Z(0, 0, pow(2, N));
return 0;
}