BOJ_S1_1074
π [S1_1074] Z
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
static StringTokenizer st;
static int N, r, c, cnt;
static int[][] arr;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
st = new StringTokenizer(br.readLine(), " ");
// λ°°μ΄μ ν¬κΈ°
N = Integer.parseInt(st.nextToken());
// ν
r = Integer.parseInt(st.nextToken());
// μ΄
c = Integer.parseInt(st.nextToken());
int temp = (int) Math.pow(2, N);
dfs(temp, 0,0);
}
static void dfs(int n, int x, int y) {
// κΈ°μ 쑰건
if (x == c && y == r) {
System.out.println(cnt);
return;
}
// μμΉλ§λ€ μ¬κ· νΈμΆ
if (y <= r && r < (y + n) && x <= c && c < (x + n)) {
int next_n = n / 2;
dfs(next_n, x, y);
dfs(next_n, x + next_n, y);
dfs(next_n, x, y + next_n);
dfs(next_n, x + next_n, y + next_n);
}
else{
cnt += n*n;
}
}
}
π€ λμ μκ°
ν΄λΉ ꡬμλ΄μ r,cκ° μνλμ§ μ²΄ν¬νλ€. λ§μ½ μ‘΄μ¬νλ©΄ ν΄λΉ ꡬμμ 4λ±λΆμΌλ‘ λλλ€.
λ§μ½ ν΄λΉ ꡬμμ μνμ§ μλλ€λ©΄ ν΄λΉκ΅¬μμ ν¬κΈ°λ§νΌ νμν μμ λν΄μ€λ€ !!
λΆν μ 볡 λ¬Έμ μ΄λ€.