문제링크
https://www.acmicpc.net/problem/1018
나의코드
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.StringTokenizer;
public class Main{
public static boolean[][] arr;
public static int min = 64;
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine()," ");
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
arr = new boolean[N][M];
for(int i = 0; i < N; i++){
String str = br.readLine();
for(int j = 0; j < M; j++){
if(str.charAt(j) == 'B'){
arr[i][j] = true;
}else{
arr[i][j] = false;
}
}
}
int row = N - 7;
int col = M - 7;
for(int i = 0; i < row; i++){
for(int j = 0; j < col; j++){
calculate(i, j);
}
}
System.out.print(min);
}
public static void calculate(int x, int y){
int x_end = x + 8;
int y_end = y + 8;
int count = 0;
Boolean BW = arr[x][y];
for(int i = x; i < x_end; i++){
for(int j = y; j < y_end; j++){
if(arr[i][j] != BW){
count++;
}
BW = !BW;
}
BW = !BW;
}
count = Math.min(count, 64 - count);
min = Math.min(count, min);
}
}
'Baekjoon Online Judge' 카테고리의 다른 글
[BOJ] 백준 1259번: 팰린드롬수 (Java) (0) | 2023.04.01 |
---|---|
[BOJ] 백준 1181번: 단어 정렬 (Java) (0) | 2023.03.31 |
[BOJ] 백준 1085번: 직사각형에서 탈출 (Java) (0) | 2023.03.29 |
[BOJ] 백준 2920번: 음계 (Java) (0) | 2023.03.28 |
[BOJ] 백준 2742번: 기찍 N (Java) (0) | 2023.03.27 |
댓글