Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

22.01.19 - [BOJ] 1074. Z #197

Closed
suhyunsim opened this issue Jan 19, 2022 · 0 comments
Closed

22.01.19 - [BOJ] 1074. Z #197

suhyunsim opened this issue Jan 19, 2022 · 0 comments
Assignees
Labels
성공 맞은 문제 실버 BOJ - 실버 재귀

Comments

@suhyunsim
Copy link
Owner

문제

핵심 아이디어

IMG_BE634C5E5DAE-1

  • 재귀를 안으로 타고 들어간다고 생각하지 말고 k + 1을 k로 구하는 방법이라고 생각하기

어려운 점, 실수

풀이

package main.java.com.poogle.BOJ.Q1074;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int r = sc.nextInt();
        int c = sc.nextInt();
        System.out.println(calculate(n, r, c));
    }

    private static int calculate(int n, int r, int c) {
        if (n == 0) return 0;
        int half = 1 << n - 1;
        if (r < half && c < half) return calculate(n - 1, r, c);
        if (r < half && c >= half) return half * half + calculate(n - 1, r, c + half);
        if (r >= half && c < half) return 2 * half * half + calculate(n - 1, r + half, c);
        return 3 * half * half + calculate(n - 1, r + half, c + half);
    }
}
@suhyunsim suhyunsim added 성공 맞은 문제 실버 BOJ - 실버 재귀 labels Jan 19, 2022
@suhyunsim suhyunsim added this to the 1월 3주 차 milestone Jan 19, 2022
@suhyunsim suhyunsim self-assigned this Jan 19, 2022
suhyunsim added a commit that referenced this issue Feb 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
성공 맞은 문제 실버 BOJ - 실버 재귀
Projects
None yet
Development

No branches or pull requests

1 participant