-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQ1074.cpp
71 lines (55 loc) · 1.08 KB
/
Q1074.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <iostream>
#include <cmath>
using namespace std;
int n, r, c;
int level;
int now_r, now_c;
int answer;
int flag;
bool chk(int level, int y, int x) {
int y1[2] = { y + pow(2, level), y };
int x1[2] = { x + pow(2, level), x };
if (r >= y1[1] && r < y1[0] && c >= x1[1] && c < x1[0])
return true;
return false;
}
void input() {
cin >> n >> r >> c;
level = n;
n = pow(2, n);
}
void dfs(int level, int now_r, int now_c) {
if (flag)
return;
// Àý´ë ¾øÀ½
if (!chk(level, now_r, now_c)) {
answer += (pow(2, level) * pow(2, level));
return;
}
if (level == 1) {
for (int i = 0; i < 2; ++i) {
for (int j = 0; j < 2; ++j) {
if (now_r + i == r && now_c + j == c) {
cout << answer;
flag = 1;
return;
}
answer++;
}
}
}
int tmp = pow(2, level - 1);
for (int i = 0; i < 2; ++i) {
for (int j = 0; j < 2; ++j) {
if (flag)
break;
dfs(level - 1, now_r + tmp * i, now_c + tmp * j);
}
if (flag)
break;
}
}
int main() {
input();
dfs(level, 0, 0);
}