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

Dltmd202 #119

Merged
merged 5 commits into from
Jul 5, 2022
Merged

Dltmd202 #119

merged 5 commits into from
Jul 5, 2022

Conversation

Dltmd202
Copy link
Contributor

@Dltmd202 Dltmd202 commented Jul 5, 2022

#118 문제풀이

2022-07-05
@Dltmd202

관련 이슈

소스코드

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static StringBuilder sb = new StringBuilder();

    public static void main(String[] args) throws IOException {
        StringTokenizer st = new StringTokenizer(br.readLine());

        int n = Integer.parseInt(st.nextToken());
        int m = Integer.parseInt(st.nextToken());
        char[][] map = new char[n][m];
        char[] checker = {'W', 'B'};

        for (int i = 0; i < n; i++) {
            map[i] = br.readLine().toCharArray();
        }

        int res = Integer.MAX_VALUE;
        for (int i = 0; i <= n - 8; i++) {
            for (int j = 0; j <= m - 8; j++) {
                res = Math.min(res, check(n, m, map, checker, 0, i, j));
                res = Math.min(res, check(n, m, map, checker, 1, i, j));
            }
        }
        System.out.println(res);
    }

    private static int check(int n, int m, char[][] map, char[] checker, int grad, int sy, int sx) {
        int modified = 0;
        int turn = grad;
        for (int i = sy; i < sy + 8; i++) {
            for (int j = sx; j < sx + 8; j++) {
                if (checker[turn % 2] != map[i][j]) {
                    modified++;
                }
                turn++;
            }
            turn++;
        }
        return modified;
    }
}

@Dltmd202 Dltmd202 merged commit 0c024c7 into master Jul 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant