File tree Expand file tree Collapse file tree 1 file changed +52
-0
lines changed
Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change 1+ ```java
2+ import java.io.*;
3+ import java.util.*;
4+ public class Main {
5+ static int R, C;
6+ public static void main(String[] args) throws IOException {
7+ BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+ StringTokenizer st = new StringTokenizer(br.readLine());
9+ int N = nextInt(st);
10+ R = nextInt(st);
11+ C = nextInt(st);
12+
13+ recur(N, 0L);
14+ }
15+
16+ private static void recur(int n, long startValue) {
17+ int quad = determine(n);
18+ long newStartValue = startValue + quad * (1L << (2*(n-1)));
19+
20+ if (n == 1){
21+ System.out.println(newStartValue);
22+ return;
23+ }
24+
25+ recur(n-1, newStartValue);
26+ }
27+
28+ private static int determine(int n) {
29+ int stand = 1 << (n-1);
30+
31+ if (R < stand && C < stand) {
32+ return 0;
33+ }
34+ if (R < stand && C >= stand) {
35+ C -= stand;
36+ return 1;
37+ }
38+ if (R >= stand && C < stand) {
39+ R -= stand;
40+ return 2;
41+ }
42+ C -= stand;
43+ R -= stand;
44+
45+ return 3;
46+ }
47+
48+ private static int nextInt(StringTokenizer st) {
49+ return Integer.parseInt(st.nextToken());
50+ }
51+ }
52+ ```
You can’t perform that action at this time.
0 commit comments