-
Notifications
You must be signed in to change notification settings - Fork 96
/
[06]_2.java
47 lines (40 loc) · 857 Bytes
/
[06]_2.java
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
import java.util.Scanner;
public class Main {
public static int N, X, Y, result = 0;
public static void solve(int n, int x, int y) {
if (n == 2) {
if (x == X && y == Y) {
System.out.println(result);
return;
}
result++;
if (x == X && y + 1 == Y) {
System.out.println(result);
return;
}
result++;
if (x + 1 == X && y == Y) {
System.out.println(result);
return;
}
result++;
if (x + 1 == X && y + 1 == Y) {
System.out.println(result);
return;
}
result++;
return;
}
solve(n / 2, x, y);
solve(n / 2, x, y + n / 2);
solve(n / 2, x + n / 2, y);
solve(n / 2, x + n / 2, y + n / 2);
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
N = sc.nextInt();
X = sc.nextInt();
Y = sc.nextInt();
solve((int) Math.pow(2, N), 0, 0);
}
}