728x90
반응형
https://www.acmicpc.net/problem/1074
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
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
static int N, r, c;
static int cnt = 0;
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());
N = (int) Math.pow(2, N);
divide(r, c, N);
}
static void divide(int row, int col, int size) {
if (size == 1) {
System.out.println(cnt);
return;
}
int n = size / 2;
if (row < n && col < n) {
cnt += n * n * 0;
divide(row, col, n);
} else if (row < n && col < n + n) {
cnt += n * n * 1;
divide(row, col - n, n);
} else if (row < n + n && col < n) {
cnt += n * n * 2;
divide(row - n, col, n);
} else if (row < n + n && col < n + n){
cnt += n * n * 3;
divide(row - n, col - n, n);
}
}
}
|
cs |
728x90
'Algorithm > BOJ' 카테고리의 다른 글
백준) 2133_타일 채우기 (0) | 2023.05.16 |
---|---|
백준) 11052_카드 구매하기 (0) | 2023.05.16 |
백준) 11003_최솟값 찾기 (2) | 2023.05.14 |
백준) 21276_계보 복원가 호석 (2) | 2023.05.13 |
백준) 1766_문제집 (1) | 2023.05.13 |