Notice
Recent Posts
문제 풀이 및 개발 공간
[백준] 1018번 체스판 다시 칠하기 (silver 4 본문
import java.io.*;
import java.util.*;
public class Main{
static String[][] temp;
static int t=0;
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st=new StringTokenizer(br.readLine());
int n=Integer.valueOf(st.nextToken());
int m=Integer.valueOf(st.nextToken());
temp=new String[n+1][m+1];
for(int i=1; i<=n; i++){
String a=br.readLine();
for(int j=1; j<=m; j++){
temp[i][j]=String.valueOf(a.charAt(j-1));
}
}
int min=Integer.MAX_VALUE;
for(int i=1; i<=n-7; i++){
for(int j=1; j<=m-7; j++){
for(int k=0; k<=7; k++){
if((i+k)%2==1){
check(i+k,j,"B","W");
}
else {
check(i + k, j ,"W", "B");
}
}
min=Math.min(min,t);
t=0;
for(int k=0; k<=7; k++){
if((i+k)%2==1){
check(i+k,j,"W","B");
}
else{
check(i+k,j,"B","W");
}
}
min=Math.min(min,t);
t=0;
}
}
bw.write(min+"");
bw.flush();
}
public static void check(int y, int x, String f, String s){
for(int i=x; i<=x+7; i++){
if((i-x)%2==0 && temp[y][i].equals(f)){
t++;
}
else if((i-x)%2==1 && temp[y][i].equals(s)){
t++;
}
}
}
}
'백준공부 > java' 카테고리의 다른 글
[백준] 1806번 부분합 (gold 4 (0) | 2023.12.20 |
---|---|
[백준] 18110번 solved.ac (silver 4 (2) | 2023.12.20 |
[백준] 1368번 물대기 (gold 2 (0) | 2023.12.19 |
[백준] 4386번 별자리 만들기 (gold 3 (0) | 2023.12.19 |
[백준] 30802번 웰컴 키드 (bronze 3 (0) | 2023.11.29 |