-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1074.cpp
43 lines (38 loc) · 869 Bytes
/
1074.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
#include <cmath>
using namespace std;
int N, r, c;
int DFS(int r, int c, int N)
{
if (N == 1)
{
return (2 * r + c);
}
if (r < pow(2, N - 1) && c < pow(2, N - 1))
{
// case 0
return DFS(r, c, N-1);
}
else if (r < pow(2, N - 1) && c >= pow(2, N - 1))
{
// case 1
return pow(4, N-1) + DFS(r, c - pow(2, N -1 ), N - 1);
}
else if (r >= pow(2, N - 1) && c < pow(2, N - 1))
{
// case 2
return 2 * pow(4, N - 1) + DFS(r - pow(2, N - 1), c, N - 1);
}
else if (r >= pow(2, N - 1) && c >= pow(2, N - 1))
{
// case 3
return 3 * pow(4, N - 1) + DFS(r - pow(2, N - 1), c - pow(2, N - 1), N - 1);
}
}
int main()
{
cin >> N >> r >> c;
// N = 1이 될때까지 호출
int result = DFS(r, c, N);
cout << result;
}