-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
51 lines (46 loc) · 1.38 KB
/
Main.java
File metadata and controls
51 lines (46 loc) · 1.38 KB
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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
static int N, R, C, cnt;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
N = Integer.parseInt(st.nextToken());
R = Integer.parseInt(st.nextToken());
C = Integer.parseInt(st.nextToken());
cnt = 0;
solution(Math.pow(2,N), 0, 0);
br.close();
}
public static void solution(double n, double x, double y){
if(n == 2){
if(x == R && y == C){
System.out.println(cnt);
return;
}
cnt++;
if(x == R && y+1 == C){
System.out.println(cnt);
return;
}
cnt++;
if(x+1 == R && y == C){
System.out.println(cnt);
return;
}
cnt++;
if(x+1 == R && y+1 == C){
System.out.println(cnt);
return;
}
cnt++;
} else {
solution(n/2, x, y);
solution(n/2, x, y+n/2);
solution(n/2, x+n/2, y);
solution(n/2, x+n/2, y+n/2);
}
}
}