Skip to content

Commit 4f8289a

Browse files
authored
[20250212] BOJ / 골드5 / Z / 설진영
1 parent 239e8df commit 4f8289a

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

Seol-JY/202502/12 BOJ G5 Z

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
```

0 commit comments

Comments
 (0)