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.02.07 - [BOJ] 1992. 쿼드트리 #207

Closed
suhyunsim opened this issue Feb 7, 2022 · 0 comments
Closed

22.02.07 - [BOJ] 1992. 쿼드트리 #207

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

Comments

@suhyunsim
Copy link
Owner

suhyunsim commented Feb 7, 2022

문제

핵심 아이디어

어려운 점, 실수

풀이

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

import java.util.Scanner;

public class Main {

    public static int[][] board;
    public static StringBuilder sb = new StringBuilder();

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        board = new int[n + 1][n + 1];
        for (int i = 0; i < n; i++) {
            String line = sc.next();
            for (int j = 0; j < n; j++) {
                board[i][j] = line.charAt(j) - '0';
            }
        }
        tree(0, 0, n);
        System.out.println(sb.toString());
    }

    private static void tree(int x, int y, int n) {
        if (check(x, y, n)) {
            sb.append(board[x][y]);
            return;
        }
        int after = n / 2;
        sb.append("(");
        tree(x, y, after);
        tree(x, y + after, after);
        tree(x + after, y, after);
        tree(x + after, y + after, after);
        sb.append(")");

    }

    private static boolean check(int x, int y, int n) {
        int value = board[x][y];
        for (int i = x; i < x + n; i++) {
            for (int j = y; j < y + n; j++) {
                if (board[i][j] != value) {
                    return false;
                }
            }
        }
        return true;
    }
}
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