-
Notifications
You must be signed in to change notification settings - Fork 0
/
1074.cpp
38 lines (30 loc) · 822 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
#include<iostream>
#include<cmath>
using namespace std;
int zrep(int n, int a, int b) {
if (n == 1) {
if (a == 0 && b == 0) return 1;
if (a == 0 && b == 1) return 2;
if (a == 1 && b == 0) return 3;
if (a == 1 && b == 1) return 4;
}
bool up, right, left, down;
up = (a < pow(2, n - 1));
right = (b >= pow(2, n - 1));
down = (a >= pow(2, n - 1));
left = (b < pow(2, n - 1));
if (up && left)
return zrep(n - 1, a, b);
if (up && right)
return pow(pow(2, n -1), 2) + zrep(n - 1, a, b - pow(2, n - 1));
if (down && left)
return pow(pow(2, n - 1), 2) * 2 + zrep(n - 1, a - pow(2, n - 1), b);
if (down && right)
return pow(pow(2, n - 1), 2) * 3 + zrep(n - 1, a - pow(2, n - 1), b - pow(2, n - 1));
}
int main() {
int n, a, b;
cin >> n >> a >> b;
cout << zrep(n, a, b) - 1;
return 0;
}