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.24 - [BOJ] 2630. 색종이 만들기 #201

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

22.01.24 - [BOJ] 2630. 색종이 만들기 #201

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

Comments

@suhyunsim
Copy link
Owner

suhyunsim commented Jan 24, 2022

문제

핵심 아이디어

  • 재귀

어려운 점, 실수

풀이

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

import java.util.Scanner;

public class Main {
    static int[] ans = new int[2];
    static int[][] board = new int[128][128];
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                board[i][j] = sc.nextInt();
            }
        }
        calculate(n, 0, 0);
        for (int i : ans) {
            System.out.println(i);
        }
    }

    private static void calculate(int n, int x, int y) {
        if (check(n, x, y)) {
            ans[board[x][y]]++;
            return;
        }
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < 2; j++) {
                calculate(n / 2, x + i * n / 2, y + j * n / 2);
            }
        }
    }

    private static boolean check(int n, int x, int y) {
        for (int i = x; i < x + n; i++) {
            for (int j = y; j < y + n; j++) {
                if (board[i][j] != board[x][y]) return false;
            }
        }
        return true;
    }

}
@suhyunsim suhyunsim added 실버 BOJ - 실버 재귀 labels Jan 24, 2022
@suhyunsim suhyunsim added this to the 1월 4주 차 milestone Jan 24, 2022
@suhyunsim suhyunsim self-assigned this Jan 24, 2022
@suhyunsim suhyunsim added the 성공 맞은 문제 label Jan 26, 2022
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