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] 1780. 종이의 개수 #202

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

22.01.24 - [BOJ] 1780. 종이의 개수 #202

suhyunsim opened this issue Jan 24, 2022 · 0 comments
Assignees
Labels
실버 BOJ - 실버 재귀

Comments

@suhyunsim
Copy link
Owner

문제

핵심 아이디어

  • 재귀

어려운 점, 실수

풀이

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

import java.util.Scanner;

public class Main {
    static int n;
    static int[][] board = new int[2200][2200];
    static int[] cnt = new int[3];

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

        for (int i : cnt) {
            System.out.println(i);
        }
    }

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

    }

    private static boolean check(int x, int y, int n) {
        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
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